Skip to content

Commit

Permalink
Merge branch 'master' into 'release'
Browse files Browse the repository at this point in the history
First Release (v0.0.1)

See merge request Coffee2Code/gebaar-libinput!1
  • Loading branch information
Coffee2CodeNL committed Feb 14, 2019
2 parents 2592c27 + 24a61c4 commit 2d8e294
Show file tree
Hide file tree
Showing 19 changed files with 579 additions and 185 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Created by .ignore support plugin (hsz.mobi)
### Personal Testing Files
gebaard.toml

### CMake template
CMakeCache.txt
CMakeFiles
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "libs/cxxopts"]
path = libs/cxxopts
url = [email protected]:jarro2783/cxxopts.git
[submodule "libs/cpptoml"]
path = libs/cpptoml
url = [email protected]:skystrife/cpptoml.git
1 change: 1 addition & 0 deletions .idea/.name

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

4 changes: 4 additions & 0 deletions .idea/encodings.xml

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

2 changes: 2 additions & 0 deletions .idea/gebaar.iml

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

7 changes: 7 additions & 0 deletions .idea/misc.xml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

7 changes: 7 additions & 0 deletions .idea/vcs.xml

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

10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.13)
project(sxgd)
project(gebaar)
set(CMAKE_VERBOSE_MAKEFILE on)
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)
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})
target_compile_options(gebaard PUBLIC ${LIBINPUT_CFLAGS_OTHER} ${UDEV_CFLAGS_OTHER})
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
1 change: 1 addition & 0 deletions libs/cxxopts
Submodule cxxopts added at 9990f7
71 changes: 71 additions & 0 deletions src/config/config.cpp
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 2d8e294

Please sign in to comment.