From 6ae5242ed5ed02b8dd5fab3183e9408f4ad52b21 Mon Sep 17 00:00:00 2001 From: Vidar Karlsen Date: Tue, 3 May 2022 16:41:11 +0000 Subject: [PATCH] Add FreeBSD support --- AutoStart/AutoStart-FreeBSD.cpp | 174 ++++++++++++++++++ AutoStart/AutoStart-FreeBSD.h | 19 ++ AutoStart/AutoStart.h | 6 +- .../CorsairHydroController.h | 4 + .../CorsairHydroControllerDetect.cpp | 4 + .../LianLiControllerDetect.cpp | 4 + .../LianLiController/LianLiUniHubController.h | 4 + OpenRGB.pro | 114 +++++++++++- i2c_smbus/i2c_smbus.h | 4 +- scripts/AppImage.patch | 22 +-- 10 files changed, 337 insertions(+), 18 deletions(-) create mode 100644 AutoStart/AutoStart-FreeBSD.cpp create mode 100644 AutoStart/AutoStart-FreeBSD.h diff --git a/AutoStart/AutoStart-FreeBSD.cpp b/AutoStart/AutoStart-FreeBSD.cpp new file mode 100644 index 00000000..fc702986 --- /dev/null +++ b/AutoStart/AutoStart-FreeBSD.cpp @@ -0,0 +1,174 @@ +#include "AutoStart-FreeBSD.h" +#include "LogManager.h" +#include "filesystem.h" + +#include +#include +#include +#include + +/*-----------------------------------------------------*\ +| FreeBSD AutoStart Implementation | +| Public Methods | +\*-----------------------------------------------------*/ + +AutoStart::AutoStart(std::string name) +{ + InitAutoStart(name); +} + +bool AutoStart::DisableAutoStart() +{ + std::error_code autostart_file_remove_errcode; + bool success = false; + + /*-------------------------------------------------*\ + | Check if the filename is valid | + \*-------------------------------------------------*/ + if(autostart_file != "") + { + /*---------------------------------------------*\ + | If file doesn't exist, disable is successful | + \*---------------------------------------------*/ + if(!filesystem::exists(autostart_file)) + { + success = true; + } + /*---------------------------------------------*\ + | Otherwise, delete the file | + \*---------------------------------------------*/ + else + { + success = filesystem::remove(autostart_file, autostart_file_remove_errcode); + + if(!success) + { + LOG_ERROR("[AutoStart] An error occurred removing the auto start file."); + } + } + } + else + { + LOG_ERROR("Could not establish correct autostart file path."); + } + + return(success); +} + +bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info) +{ + bool success = false; + + /*-------------------------------------------------*\ + | Check if the filename is valid | + \*-------------------------------------------------*/ + if(autostart_file != "") + { + std::ofstream autostart_file_stream(autostart_file, std::ios::out | std::ios::trunc); + + /*---------------------------------------------*\ + | Error out if the file could not be opened | + \*---------------------------------------------*/ + if(!autostart_file_stream) + { + LOG_ERROR("Could not open %s for writing.", autostart_file.c_str()); + success = false; + } + /*---------------------------------------------*\ + | Otherwise, write the file | + \*---------------------------------------------*/ + else + { + //autostart_file_stream << desktop_file; + autostart_file_stream.close(); + success = !autostart_file_stream.fail(); + + if (!success) + { + LOG_ERROR("An error occurred writing the auto start file."); + } + } + } + else + { + LOG_ERROR("Could not establish correct autostart file path."); + } + + return(success); +} + +bool AutoStart::IsAutoStartEnabled() +{ + /*-------------------------------------------------*\ + | Check if the filename is valid | + \*-------------------------------------------------*/ + if(autostart_file != "") + { + return(filesystem::exists(autostart_file)); + } + else + { + return(false); + } +} + +std::string AutoStart::GetExePath() +{ + /*-------------------------------------------------*\ + | Create the OpenRGB executable path | + \*-------------------------------------------------*/ + char exepath[ PATH_MAX ]; + + ssize_t count = readlink("/proc/self/exe", exepath, PATH_MAX); + + return(std::string(exepath, (count > 0) ? count : 0)); +} + +void AutoStart::InitAutoStart(std::string name) +{ + std::string autostart_dir; + + autostart_name = name; + + /*-------------------------------------------------*\ + | Get home and config paths | + \*-------------------------------------------------*/ + const char *xdg_config_home = getenv("XDG_CONFIG_HOME"); + const char *home = getenv("HOME"); + + /*-------------------------------------------------*\ + | Determine where the autostart .desktop files are | + | kept | + \*-------------------------------------------------*/ + if(xdg_config_home != NULL) + { + autostart_dir = xdg_config_home; + autostart_dir = autostart_dir + "/autostart/"; + } + else if(home != NULL) + { + autostart_dir = home; + autostart_dir = autostart_dir + "/.config/autostart/"; + } + + /*-------------------------------------------------*\ + | Check if the filename is valid | + \*-------------------------------------------------*/ + if(autostart_dir != "") + { + std::error_code ec; + + bool success = true; + + if(!filesystem::exists(autostart_dir)) + { + success = filesystem::create_directories(autostart_dir, ec); + } + + if(success) + { + autostart_file = autostart_dir + autostart_name + ".desktop"; + } + } +} + diff --git a/AutoStart/AutoStart-FreeBSD.h b/AutoStart/AutoStart-FreeBSD.h new file mode 100644 index 00000000..1a90ec31 --- /dev/null +++ b/AutoStart/AutoStart-FreeBSD.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include "AutoStart.h" + +class AutoStart: public AutoStartInterface +{ +public: + AutoStart(std::string name); + + bool DisableAutoStart(); + bool EnableAutoStart(AutoStartInfo autostart_info); + bool IsAutoStartEnabled(); + std::string GetExePath(); + +private: + void InitAutoStart(std::string name); + std::string GenerateLaunchAgentFile(AutoStartInfo autostart_info); +}; diff --git a/AutoStart/AutoStart.h b/AutoStart/AutoStart.h index f2dda1fb..7b37e7c3 100644 --- a/AutoStart/AutoStart.h +++ b/AutoStart/AutoStart.h @@ -37,4 +37,8 @@ protected: #ifdef __APPLE__ #include "AutoStart-MacOS.h" -#endif \ No newline at end of file +#endif + +#ifdef __FreeBSD__ +#include "AutoStart-FreeBSD.h" +#endif diff --git a/Controllers/CorsairHydroController/CorsairHydroController.h b/Controllers/CorsairHydroController/CorsairHydroController.h index f72f7e40..a6e9a98b 100644 --- a/Controllers/CorsairHydroController/CorsairHydroController.h +++ b/Controllers/CorsairHydroController/CorsairHydroController.h @@ -6,7 +6,11 @@ #include "RGBController.h" #include +#ifdef __FreeBSD__ +#include +#else #include +#endif #pragma once diff --git a/Controllers/CorsairHydroController/CorsairHydroControllerDetect.cpp b/Controllers/CorsairHydroController/CorsairHydroControllerDetect.cpp index 5bfb15d8..08b31e03 100644 --- a/Controllers/CorsairHydroController/CorsairHydroControllerDetect.cpp +++ b/Controllers/CorsairHydroController/CorsairHydroControllerDetect.cpp @@ -3,7 +3,11 @@ #include "RGBController.h" #include "RGBController_CorsairHydro.h" #include +#ifdef __FreeBSD__ +#include +#else #include +#endif /*-----------------------------------------------------*\ | Corsair vendor ID | diff --git a/Controllers/LianLiController/LianLiControllerDetect.cpp b/Controllers/LianLiController/LianLiControllerDetect.cpp index 62f25f5c..941f3f3d 100644 --- a/Controllers/LianLiController/LianLiControllerDetect.cpp +++ b/Controllers/LianLiController/LianLiControllerDetect.cpp @@ -15,7 +15,11 @@ #include "RGBController_LianLiUniHub.h" #include "ResourceManager.h" +#ifdef __FreeBSD__ +#include +#else #include +#endif #define UNI_HUB_VID 0x0CF2 #define UNI_HUB_PID 0x7750 diff --git a/Controllers/LianLiController/LianLiUniHubController.h b/Controllers/LianLiController/LianLiUniHubController.h index 74de8c74..76fc36a6 100644 --- a/Controllers/LianLiController/LianLiUniHubController.h +++ b/Controllers/LianLiController/LianLiUniHubController.h @@ -15,7 +15,11 @@ #include "RGBController.h" +#ifdef __FreeBSD__ +#include +#else #include +#endif /*----------------------------------------------------------------------------*\ | Global definitions. | diff --git a/OpenRGB.pro b/OpenRGB.pro index ef386779..e65d4e88 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -156,6 +156,11 @@ INCLUDEPATH += RGBController/ \ qt/ +contains(QMAKE_PLATFORM, freebsd) { + INCLUDEPATH -= \ + Controllers/GigabyteRGBFusion2GPUController/ +} + HEADERS += \ Colors.h \ dependencies/ColorWheel/ColorWheel.h \ @@ -542,6 +547,16 @@ HEADERS += RGBController/RGBControllerKeyNames.h \ RGBController/RGBController_Network.h \ +contains(QMAKE_PLATFORM, freebsd) { + HEADERS -= \ + Controllers/GigabyteRGBFusion2GPUController/GigabyteRGBFusion2GPUController.h \ + Controllers/GigabyteRGBFusion2GPUController/RGBController_GigabyteRGBFusion2GPU.h \ + Controllers/HoltekController/HoltekA070Controller.h \ + Controllers/HoltekController/HoltekA1FAController.h \ + Controllers/HoltekController/RGBController_HoltekA070.h \ + Controllers/HoltekController/RGBController_HoltekA1FA.h +} + SOURCES += \ dependencies/Swatches/swatches.cpp \ dependencies/dmiinfo.cpp \ @@ -1037,6 +1052,18 @@ SOURCES += RGBController/RGBControllerKeyNames.cpp \ RGBController/RGBController_Network.cpp \ +contains(QMAKE_PLATFORM, freebsd) { + SOURCES -= \ + Controllers/GigabyteRGBFusion2GPUController/GigabyteRGBFusion2GPUController.cpp \ + Controllers/GigabyteRGBFusion2GPUController/GigabyteRGBFusion2GPUControllerDetect.cpp \ + Controllers/GigabyteRGBFusion2GPUController/RGBController_GigabyteRGBFusion2GPU.cpp \ + Controllers/HoltekController/HoltekA070Controller.cpp \ + Controllers/HoltekController/HoltekA1FAController.cpp \ + Controllers/HoltekController/HoltekControllerDetect.cpp \ + Controllers/HoltekController/RGBController_HoltekA070.cpp \ + Controllers/HoltekController/RGBController_HoltekA1FA.cpp +} + RESOURCES += \ qt/resources.qrc @@ -1288,7 +1315,7 @@ win32:contains(QMAKE_TARGET.arch, x86) { #-----------------------------------------------------------------------------------------------# # Linux-specific Configuration # #-----------------------------------------------------------------------------------------------# -unix:!macx { +contains(QMAKE_PLATFORM, linux) { TARGET = $$lower($$TARGET) INCLUDEPATH += \ @@ -1401,6 +1428,91 @@ unix:!macx { INSTALLS += target desktop icon metainfo udev_rules } +#-----------------------------------------------------------------------------------------------# +# FreeBSD-specific Configuration # +#-----------------------------------------------------------------------------------------------# +contains(QMAKE_PLATFORM, freebsd) { + TARGET = $$lower($$TARGET) + + INCLUDEPATH += \ + Controllers/FaustusController \ + Controllers/LinuxLEDController \ + + HEADERS += \ + AutoStart/AutoStart-FreeBSD.h \ + Controllers/ENESMBusController/ENESMBusInterface/ENESMBusInterface_SpectrixS40G.h \ + Controllers/FaustusController/RGBController_Faustus.h \ + Controllers/LinuxLEDController/LinuxLEDController.h \ + Controllers/LinuxLEDController/RGBController_LinuxLED.h \ + Controllers/OpenRazerController/RGBController_OpenRazer.h \ + + LIBS += \ + -lusb \ + -lmbedx509 \ + -lmbedtls \ + -lmbedcrypto \ + + COMPILER_VERSION = $$system($$QMAKE_CXX " -dumpversion") + if (!versionAtLeast(COMPILER_VERSION, "9")) { + LIBS += -lstdc++fs + } + + #-------------------------------------------------------------------------------------------# + # Determine which hidapi to use based on availability # + # Prefer hidraw backend, then libusb # + #-------------------------------------------------------------------------------------------# + packagesExist(hidapi-hidraw) { + LIBS += -lhidapi-hidraw + + #---------------------------------------------------------------------------------------# + # hidapi-hidraw >= 0.10.1 supports USAGE/USAGE_PAGE # + # Define USE_HID_USAGE if hidapi-hidraw supports it # + #---------------------------------------------------------------------------------------# + HIDAPI_HIDRAW_VERSION = $$system($$PKG_CONFIG --modversion hidapi-hidraw) + if(versionAtLeast(HIDAPI_HIDRAW_VERSION, "0.10.1")) { + DEFINES += USE_HID_USAGE + } + } else { + packagesExist(hidapi-libusb) { + LIBS += -lhidapi-libusb + } else { + LIBS += -lhidapi + } + } + + SOURCES += \ + dependencies/hueplusplus-1.0.0/src/LinHttpHandler.cpp \ + serial_port/find_usb_serial_port_linux.cpp \ + AutoStart/AutoStart-FreeBSD.cpp \ + Controllers/ENESMBusController/XPGSpectrixS40GDetect.cpp \ + Controllers/ENESMBusController/ENESMBusInterface/ENESMBusInterface_SpectrixS40G.cpp \ + Controllers/FaustusController/RGBController_Faustus.cpp \ + Controllers/LinuxLEDController/LinuxLEDController.cpp \ + Controllers/LinuxLEDController/LinuxLEDControllerDetect.cpp \ + Controllers/LinuxLEDController/RGBController_LinuxLED.cpp \ + Controllers/OpenRazerController/OpenRazerDetect.cpp \ + Controllers/OpenRazerController/RGBController_OpenRazer.cpp \ + + #-------------------------------------------------------------------------------------------# + # Set up install paths # + # These install paths are used for AppImage and .deb packaging # + #-------------------------------------------------------------------------------------------# + isEmpty(PREFIX) { + PREFIX = /usr + } + + target.path=$$PREFIX/bin/ + desktop.path=$$PREFIX/share/applications/ + desktop.files+=qt/OpenRGB.desktop + icon.path=$$PREFIX/share/icons/hicolor/128x128/apps/ + icon.files+=qt/OpenRGB.png + metainfo.path=$$PREFIX/share/metainfo/ + metainfo.files+=qt/org.openrgb.OpenRGB.metainfo.xml + rules.path=$$PREFIX/lib/udev/rules.d/ + rules.files+=60-openrgb.rules + INSTALLS += target desktop icon metainfo rules +} + unix:!macx:CONFIG(asan) { message("ASan Mode") QMAKE_CFLAGS=-fsanitize=address diff --git a/i2c_smbus/i2c_smbus.h b/i2c_smbus/i2c_smbus.h index 0da27959..50750c1b 100644 --- a/i2c_smbus/i2c_smbus.h +++ b/i2c_smbus/i2c_smbus.h @@ -41,7 +41,7 @@ union i2c_smbus_data #endif /* __linux__ */ -#ifdef __APPLE__ +#if defined(__APPLE___) || defined(__FreeBSD__) //Data for SMBus Messages #define I2C_SMBUS_BLOCK_MAX 32 @@ -53,7 +53,7 @@ union i2c_smbus_data u8 block[I2C_SMBUS_BLOCK_MAX + 2]; }; -#endif /* __APPLE__ */ +#endif /* __APPLE__ or __FreeBSD__ */ // i2c_smbus_xfer read or write markers #define I2C_SMBUS_READ 1 diff --git a/scripts/AppImage.patch b/scripts/AppImage.patch index 95dc01f7..4ee2eef6 100644 --- a/scripts/AppImage.patch +++ b/scripts/AppImage.patch @@ -1,23 +1,17 @@ - - -diff --git a/OpenRGB.pro b/OpenRGB.pro -index 6295344a..d09bed44 100644 ---- a/OpenRGB.pro -+++ b/OpenRGB.pro -@@ -639,8 +639,6 @@ win32:contains(QMAKE_TARGET.arch, x86) { +--- a/OpenRGB.pro 2022-05-02 15:26:15.375947000 +0200 ++++ b/OpenRGB.pro 2022-05-02 15:29:01.997135000 +0200 +@@ -1310,8 +1310,6 @@ # Linux-specific Configuration # #-----------------------------------------------------------------------------------------------# - unix:!macx { + contains(QMAKE_PLATFORM, linux) { - TARGET = $$lower($$TARGET) - INCLUDEPATH += \ Controllers/FaustusController \ - -diff --git a/qt/OpenRGB.desktop b/qt/OpenRGB.desktop -index bd71a38a..b4a0f86a 100644 ---- a/qt/OpenRGB.desktop -+++ b/qt/OpenRGB.desktop -@@ -3,7 +3,7 @@ Type=Application + Controllers/LinuxLEDController \ +--- a/qt/OpenRGB.desktop 2022-05-02 15:25:52.150332000 +0200 ++++ b/qt/OpenRGB.desktop 2022-05-02 15:28:27.749598000 +0200 +@@ -3,7 +3,7 @@ Encoding=UTF-8 Name=OpenRGB Comment=Control RGB lighting