Skip to content

Commit 24a61c4

Browse files
committed
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
1 parent 81ac92f commit 24a61c4

File tree

12 files changed

+399
-219
lines changed

12 files changed

+399
-219
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Created by .ignore support plugin (hsz.mobi)
1+
### Personal Testing Files
2+
gebaard.toml
3+
24
### CMake template
35
CMakeCache.txt
46
CMakeFiles

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "libs/cxxopts"]
22
path = libs/cxxopts
33
url = [email protected]:jarro2783/cxxopts.git
4+
[submodule "libs/cpptoml"]
5+
path = libs/cpptoml
6+
url = [email protected]:skystrife/cpptoml.git

.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS on)
55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
77

8-
add_executable(gebaard src/main.cpp src/io/input.cpp src/io/input.hpp)
8+
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)
99

1010
find_package(PkgConfig)
1111
if (PKG_CONFIG_FOUND)
@@ -15,6 +15,6 @@ endif ()
1515
find_package(udev)
1616
find_package(spdlog)
1717

18-
target_link_libraries(gebaard ${LIBINPUT_LIBRARIES} ${UDEV_LIBRARIES})
19-
target_include_directories(gebaard PUBLIC ${LIBINPUT_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS} libs/cxxopts/include)
18+
target_link_libraries(gebaard ${LIBINPUT_LIBRARIES} ${UDEV_LIBRARIES} stdc++fs)
19+
target_include_directories(gebaard PUBLIC ${LIBINPUT_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS} libs/cxxopts/include libs/cpptoml/include)
2020
target_compile_options(gebaard PUBLIC ${LIBINPUT_CFLAGS_OTHER} ${UDEV_CFLAGS_OTHER})

libs/cpptoml

Submodule cpptoml added at fededad

src/config/config.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
gebaar
3+
Copyright (C) 2019 coffee2code
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
20+
#include <zconf.h>
21+
#include "config.h"
22+
23+
bool gebaar::config::Config::find_config_file()
24+
{
25+
auto true_path = std::filesystem::path(config_file_path);
26+
return std::filesystem::exists(true_path);
27+
}
28+
29+
void gebaar::config::Config::load_config()
30+
{
31+
if (find_home_folder()) {
32+
if (find_config_file()) {
33+
config = cpptoml::parse_file(std::filesystem::path(config_file_path));
34+
swipe_three_up_command = *config->get_qualified_as<std::string>("commands.swipe.three.up");
35+
swipe_three_down_command = *config->get_qualified_as<std::string>("commands.swipe.three.down");
36+
swipe_three_left_command = *config->get_qualified_as<std::string>("commands.swipe.three.left");
37+
swipe_three_right_command = *config->get_qualified_as<std::string>("commands.swipe.three.right");
38+
swipe_four_up_command = *config->get_qualified_as<std::string>("commands.swipe.four.up");
39+
swipe_four_down_command = *config->get_qualified_as<std::string>("commands.swipe.four.down");
40+
swipe_four_left_command = *config->get_qualified_as<std::string>("commands.swipe.four.left");
41+
swipe_four_right_command = *config->get_qualified_as<std::string>("commands.swipe.four.right");
42+
loaded = true;
43+
}
44+
}
45+
46+
}
47+
48+
bool gebaar::config::Config::find_home_folder()
49+
{
50+
const char* temp_path;
51+
temp_path = getenv("XDG_CONFIG_HOME");
52+
if (temp_path==nullptr) {
53+
temp_path = getenv("HOME");
54+
if (temp_path==nullptr) {
55+
temp_path = getpwuid(getuid())->pw_dir;
56+
}
57+
}
58+
if (temp_path!=nullptr) {
59+
config_file_path = temp_path;
60+
config_file_path.append("/.config/gebaar/gebaard.toml");
61+
return true;
62+
}
63+
return false;
64+
}
65+
66+
gebaar::config::Config::Config()
67+
{
68+
if (!loaded) {
69+
load_config();
70+
}
71+
}

src/config/config.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
gebaar
3+
Copyright (C) 2019 coffee2code
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef GEBAAR_CONFIG_H
20+
#define GEBAAR_CONFIG_H
21+
22+
#include <cpptoml.h>
23+
#include <filesystem>
24+
#include <pwd.h>
25+
#include <iostream>
26+
27+
namespace gebaar::config {
28+
class Config {
29+
public:
30+
Config();
31+
32+
bool loaded = false;
33+
34+
void load_config();
35+
36+
std::string swipe_four_up_command;
37+
std::string swipe_four_down_command;
38+
std::string swipe_four_left_command;
39+
std::string swipe_four_right_command;
40+
std::string swipe_three_up_command;
41+
std::string swipe_three_down_command;
42+
std::string swipe_three_left_command;
43+
std::string swipe_three_right_command;
44+
private:
45+
bool find_config_file();
46+
47+
bool find_home_folder();
48+
49+
std::string config_file_path;
50+
std::shared_ptr<cpptoml::table> config;
51+
};
52+
}
53+
#endif //GEBAAR_CONFIG_H

src/daemonizer.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
gebaar
3+
Copyright (C) 2019 coffee2code
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
20+
#include "daemonizer.h"
21+
22+
23+
bool gebaar::daemonizer::Daemonizer::daemonize()
24+
{
25+
pid_t pid = 0;
26+
pid = fork();
27+
if (pid<0) {
28+
exit(EXIT_FAILURE);
29+
}
30+
if (pid>0) {
31+
exit(EXIT_SUCCESS);
32+
}
33+
if (setsid()<0) {
34+
// Boo.
35+
}
36+
signal(SIGCHLD, SIG_IGN);
37+
signal(SIGTRAP, SIG_IGN);
38+
pid = fork();
39+
if (pid<0) {
40+
exit(EXIT_FAILURE);
41+
}
42+
if (pid>0) {
43+
exit(EXIT_SUCCESS);
44+
}
45+
umask(0);
46+
if ((chdir("/"))<0) {
47+
return false;
48+
}
49+
close(STDOUT_FILENO);
50+
close(STDIN_FILENO);
51+
close(STDERR_FILENO);
52+
if (getpid()!=getsid(getpid())) {
53+
//
54+
}
55+
return true;
56+
57+
}
58+
59+
gebaar::daemonizer::Daemonizer::Daemonizer() = default;
60+
61+
gebaar::daemonizer::Daemonizer::~Daemonizer() = default;

src/daemonizer.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
gebaar
3+
Copyright (C) 2019 coffee2code
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
#include <csignal>
19+
#include <unistd.h>
20+
#include <cstdlib>
21+
#include <sys/stat.h>
22+
23+
#ifndef GEBAAR_DAEMONIZER_H
24+
#define GEBAAR_DAEMONIZER_H
25+
namespace gebaar::daemonizer {
26+
class Daemonizer {
27+
public:
28+
Daemonizer();
29+
~Daemonizer();
30+
bool daemonize();
31+
};
32+
}
33+
#endif //GEBAAR_DAEMONIZER_H

0 commit comments

Comments
 (0)