Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Working state commit
- Add cxxtoml library (checkout @ v0.1.1)
- Remove all spdlog references
- Add configuration file support
- Further compartmentalize input system
- Add support for running commands
- Add daemonizing mode
  • Loading branch information
Coffee2CodeNL committed Feb 14, 2019
1 parent 81ac92f commit 24a61c4
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 219 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,4 +1,6 @@
# Created by .ignore support plugin (hsz.mobi)
### Personal Testing Files
gebaard.toml

### CMake template
CMakeCache.txt
CMakeFiles
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
@@ -1,3 +1,6 @@
[submodule "libs/cxxopts"]
path = libs/cxxopts
url = git@github.com:jarro2783/cxxopts.git
[submodule "libs/cpptoml"]
path = libs/cpptoml
url = git@github.com:skystrife/cpptoml.git
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions CMakeLists.txt
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS on)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

add_executable(gebaard src/main.cpp src/io/input.cpp src/io/input.hpp)
add_executable(gebaard src/main.cpp src/io/input.cpp src/io/input.h src/config/config.cpp src/config/config.h src/daemonizer.cpp src/daemonizer.h)

find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
Expand All @@ -15,6 +15,6 @@ endif ()
find_package(udev)
find_package(spdlog)

target_link_libraries(gebaard ${LIBINPUT_LIBRARIES} ${UDEV_LIBRARIES})
target_include_directories(gebaard PUBLIC ${LIBINPUT_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS} libs/cxxopts/include)
target_link_libraries(gebaard ${LIBINPUT_LIBRARIES} ${UDEV_LIBRARIES} stdc++fs)
target_include_directories(gebaard PUBLIC ${LIBINPUT_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS} libs/cxxopts/include libs/cpptoml/include)
target_compile_options(gebaard PUBLIC ${LIBINPUT_CFLAGS_OTHER} ${UDEV_CFLAGS_OTHER})
1 change: 1 addition & 0 deletions libs/cpptoml
Submodule cpptoml added at fededa
71 changes: 71 additions & 0 deletions src/config/config.cpp
@@ -0,0 +1,71 @@
/*
gebaar
Copyright (C) 2019 coffee2code
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include <zconf.h>
#include "config.h"

bool gebaar::config::Config::find_config_file()
{
auto true_path = std::filesystem::path(config_file_path);
return std::filesystem::exists(true_path);
}

void gebaar::config::Config::load_config()
{
if (find_home_folder()) {
if (find_config_file()) {
config = cpptoml::parse_file(std::filesystem::path(config_file_path));
swipe_three_up_command = *config->get_qualified_as<std::string>("commands.swipe.three.up");
swipe_three_down_command = *config->get_qualified_as<std::string>("commands.swipe.three.down");
swipe_three_left_command = *config->get_qualified_as<std::string>("commands.swipe.three.left");
swipe_three_right_command = *config->get_qualified_as<std::string>("commands.swipe.three.right");
swipe_four_up_command = *config->get_qualified_as<std::string>("commands.swipe.four.up");
swipe_four_down_command = *config->get_qualified_as<std::string>("commands.swipe.four.down");
swipe_four_left_command = *config->get_qualified_as<std::string>("commands.swipe.four.left");
swipe_four_right_command = *config->get_qualified_as<std::string>("commands.swipe.four.right");
loaded = true;
}
}

}

bool gebaar::config::Config::find_home_folder()
{
const char* temp_path;
temp_path = getenv("XDG_CONFIG_HOME");
if (temp_path==nullptr) {
temp_path = getenv("HOME");
if (temp_path==nullptr) {
temp_path = getpwuid(getuid())->pw_dir;
}
}
if (temp_path!=nullptr) {
config_file_path = temp_path;
config_file_path.append("/.config/gebaar/gebaard.toml");
return true;
}
return false;
}

gebaar::config::Config::Config()
{
if (!loaded) {
load_config();
}
}
53 changes: 53 additions & 0 deletions src/config/config.h
@@ -0,0 +1,53 @@
/*
gebaar
Copyright (C) 2019 coffee2code
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GEBAAR_CONFIG_H
#define GEBAAR_CONFIG_H

#include <cpptoml.h>
#include <filesystem>
#include <pwd.h>
#include <iostream>

namespace gebaar::config {
class Config {
public:
Config();

bool loaded = false;

void load_config();

std::string swipe_four_up_command;
std::string swipe_four_down_command;
std::string swipe_four_left_command;
std::string swipe_four_right_command;
std::string swipe_three_up_command;
std::string swipe_three_down_command;
std::string swipe_three_left_command;
std::string swipe_three_right_command;
private:
bool find_config_file();

bool find_home_folder();

std::string config_file_path;
std::shared_ptr<cpptoml::table> config;
};
}
#endif //GEBAAR_CONFIG_H
61 changes: 61 additions & 0 deletions src/daemonizer.cpp
@@ -0,0 +1,61 @@
/*
gebaar
Copyright (C) 2019 coffee2code
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "daemonizer.h"


bool gebaar::daemonizer::Daemonizer::daemonize()
{
pid_t pid = 0;
pid = fork();
if (pid<0) {
exit(EXIT_FAILURE);
}
if (pid>0) {
exit(EXIT_SUCCESS);
}
if (setsid()<0) {
// Boo.
}
signal(SIGCHLD, SIG_IGN);
signal(SIGTRAP, SIG_IGN);
pid = fork();
if (pid<0) {
exit(EXIT_FAILURE);
}
if (pid>0) {
exit(EXIT_SUCCESS);
}
umask(0);
if ((chdir("/"))<0) {
return false;
}
close(STDOUT_FILENO);
close(STDIN_FILENO);
close(STDERR_FILENO);
if (getpid()!=getsid(getpid())) {
//
}
return true;

}

gebaar::daemonizer::Daemonizer::Daemonizer() = default;

gebaar::daemonizer::Daemonizer::~Daemonizer() = default;
33 changes: 33 additions & 0 deletions src/daemonizer.h
@@ -0,0 +1,33 @@
/*
gebaar
Copyright (C) 2019 coffee2code
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <csignal>
#include <unistd.h>
#include <cstdlib>
#include <sys/stat.h>

#ifndef GEBAAR_DAEMONIZER_H
#define GEBAAR_DAEMONIZER_H
namespace gebaar::daemonizer {
class Daemonizer {
public:
Daemonizer();
~Daemonizer();
bool daemonize();
};
}
#endif //GEBAAR_DAEMONIZER_H

0 comments on commit 24a61c4

Please sign in to comment.