Skip to content

Commit

Permalink
Merge pull request PixlOne#369 from PixlOne/cxx2a-fixes
Browse files Browse the repository at this point in the history
Fix c++2a compatibility
  • Loading branch information
PixlOne authored May 3, 2023
2 parents 4c406c7 + 0945fa1 commit 2df4351
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ Default location for the configuration file is /etc/logid.cfg, but another can b

## Dependencies

This project requires a C++17 compiler, `cmake`, `libevdev`, `libudev`, `glib`, and `libconfig`.
This project requires a C++20 compiler, `cmake`, `libevdev`, `libudev`, `glib`, and `libconfig`.
For popular distributions, I've included commands below.

**Arch Linux:** `sudo pacman -S cmake libevdev libconfig pkgconf glib2`
**Arch Linux:** `sudo pacman -S base-devel cmake g++ libevdev libconfig pkgconf glib2`

**Debian/Ubuntu:** `sudo apt install cmake libevdev-dev libudev-dev libconfig++-dev libglib2.0`
**Debian/Ubuntu:** `sudo apt install git cmake g++ libevdev-dev libudev-dev libconfig++-dev libglib2.0-dev`

**Fedora:** `sudo dnf install cmake libevdev-devel systemd-devel libconfig-devel gcc-c++ glib2`

**Gentoo Linux:** `sudo emerge dev-libs/libconfig dev-libs/libevdev dev-libs/glib dev-util/cmake virtual/libudev`

**Solus:** `sudo eopkg install libevdev-devel libconfig-devel libgudev-devel glib2`
**Solus:** `sudo eopkg install cmake libevdev-devel libconfig-devel libgudev-devel glib2`

**openSUSE:** `sudo zypper install cmake libevdev-devel systemd-devel libconfig-devel gcc-c++ libconfig++-devel libudev-devel glib2`

Expand Down
2 changes: 1 addition & 1 deletion src/logid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ find_package(PkgConfig REQUIRED)
add_executable(logid
logid.cpp
util/log.cpp
config/util.cpp
config/config.cpp
InputDevice.cpp
DeviceManager.cpp
Device.cpp
Expand Down
6 changes: 5 additions & 1 deletion src/logid/config/util.cpp → src/logid/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
*
*/

#include <config/types.h>
#include <config/schema.h>
#include <util/log.h>

using namespace logid;

const char config::keys::name[] = "name";
const char config::keys::cid[] = "cid";
const char config::keys::direction[] = "direction";

void config::logError(const libconfig::Setting& setting, std::exception& e) {
logPrintf(WARN, "Error at line %d: %s", setting.getSourceLine(), e.what());
}
14 changes: 7 additions & 7 deletions src/logid/config/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
#include <utility>

namespace logid::config {
template<size_t N>
struct string_literal {
constexpr string_literal(const char (& str)[N]) {
std::copy_n(str, N, value);
}
struct string_literal { };

char value[N]{};
template<const char* str>
struct string_literal_of : public string_literal {
constexpr static const char* value = str;
};

template<class T>
Expand All @@ -46,10 +44,12 @@ namespace logid::config {
};

// Warning: map must be a variant of groups or a group
template<typename K, typename V, string_literal KeyName,
template<typename K, typename V, typename KeyName,
typename Compare=typename std::map<K, V>::key_compare,
typename Allocator=typename std::map<K, V>::allocator_type>
class map : public std::map<K, V, Compare, Allocator> {
static_assert(std::is_base_of<string_literal, KeyName>::value,
"KeyName must be a string_literal");
public:
template<typename... Args>
explicit map(Args... args) :
Expand Down
13 changes: 9 additions & 4 deletions src/logid/config/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ namespace logid::actions {
}

namespace logid::config {
struct keys {
static const char name[];
static const char cid[];
static const char direction[];
};

struct NoAction : public signed_group<std::string> {
typedef actions::NullAction action;
Expand Down Expand Up @@ -213,7 +218,7 @@ namespace logid::config {

struct GestureAction : public signed_group<std::string> {
typedef actions::GestureAction action;
std::optional<map<std::string, Gesture, "direction",
std::optional<map<std::string, Gesture, string_literal_of<keys::direction>,
less_caseless<std::string>>> gestures;

GestureAction() : signed_group<std::string>(
Expand Down Expand Up @@ -284,7 +289,7 @@ namespace logid::config {
&ThumbWheel::tap) {}
};

typedef map<uint16_t, Button, "cid"> RemapButton;
typedef map<uint16_t, Button, string_literal_of<keys::cid>> RemapButton;

struct Profile : public group {
std::optional<DPI> dpi;
Expand All @@ -302,7 +307,7 @@ namespace logid::config {

struct Device : public group {
ipcgull::property<std::string> default_profile;
map<std::string, Profile, "name"> profiles;
map<std::string, Profile, string_literal_of<keys::name>> profiles;

Device() : group({"default_profile", "profiles"},
&Device::default_profile,
Expand All @@ -313,7 +318,7 @@ namespace logid::config {

struct Config : public group {
std::optional<map<std::string,
std::variant<Device, Profile>, "name">> devices;
std::variant<Device, Profile>, string_literal_of<keys::name>>> devices;
std::optional<std::set<uint16_t>> ignore;
std::optional<double> io_timeout;
std::optional<int> workers;
Expand Down
6 changes: 3 additions & 3 deletions src/logid/config/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ namespace logid::config {
}
};

template<typename K, typename V, string_literal KeyName,
template<typename K, typename V, typename KeyName,
typename Cmp, typename Alloc>
struct config_io<map<K, V, KeyName, Cmp, Alloc>> {
static inline map<K, V, KeyName, Cmp, Alloc> get(
Expand All @@ -359,7 +359,7 @@ namespace logid::config {
for (int i = 0; i < size; ++i) {
auto& s = setting[i];
try {
t.emplace(config_io<K>::get(s.lookup(KeyName.value)),
t.emplace(config_io<K>::get(s.lookup(KeyName::value)),
config_io<V>::get(s));
} catch (libconfig::SettingException& e) {}
}
Expand All @@ -378,7 +378,7 @@ namespace logid::config {
for (auto& x: t) {
auto& s = setting.add(libconfig::Setting::TypeGroup);
config_io<V>::set(s, x.second);
config_io<K>::set(s, KeyName.value, x.first);
config_io<K>::set(s, KeyName::value, x.first);
}
}

Expand Down

0 comments on commit 2df4351

Please sign in to comment.