* Use a requirements.txt

* Add initial travis configuration

* Attempt fix travis configuration

* Attempt fix g++ error

* Bugfix missing path dir on autostart

* Attempt install build-essential instead of g++

* Add missing psutil from requirements

* Modify README

* Attempt fix build errors in travis

* Update README

* Add simple build badges
This commit is contained in:
Rico Tiongson authored and GitHub committed 2019-03-08 19:57:10 +08:00
1 parent adcb3d5e02
commit 044e215d97
21 files changed
+709 -593

No files matched your search

+9 -12
View File
@@ -4,20 +4,17 @@
#include <map> // std::map
#include <string> // std::string
extern "C"
namespace comfortable_swipe
{
namespace comfortable_swipe
namespace service
{
namespace service
{
void buffer();
void debug();
void help();
void restart();
void start();
void stop();
void status();
}
void buffer();
void debug();
void help();
void restart();
void start();
void stop();
void status();
}
}
+59 -50
View File
@@ -2,60 +2,69 @@
#define __COMFORTABLE_SWIPE__service_python__
#include "_index.hpp"
#include <Python.h>
extern "C"
{
#include <Python.h>
}
// export as python module
namespace comfortable_swipe::service::python
namespace comfortable_swipe
{
#define __comfortable_swipe_void_method(method) \
static PyObject * \
method(PyObject * self, PyObject * args) \
{ \
comfortable_swipe::service::method(); \
Py_RETURN_NONE; \
namespace service
{
namespace python
{
#define __comfortable_swipe_void_method(method) \
static PyObject * \
method(PyObject * self, PyObject * args) \
{ \
comfortable_swipe::service::method(); \
Py_RETURN_NONE; \
}
// create the python method signatures
__comfortable_swipe_void_method(status);
__comfortable_swipe_void_method(start);
__comfortable_swipe_void_method(stop);
__comfortable_swipe_void_method(restart);
// __comfortable_swipe_void_method(autostart);
__comfortable_swipe_void_method(buffer);
__comfortable_swipe_void_method(help);
// __comfortable_swipe_void_method(config);
__comfortable_swipe_void_method(debug);
#undef __comfortable_swipe_void_method
// create the method list for C++
static PyMethodDef methods[] =
{
{ "status", &status, METH_VARARGS , "checks status of program, autostart, and config" },
{ "start", &start, METH_VARARGS , "starts 3/4-finger gesture service" },
{ "stop", &stop, METH_VARARGS , "stops 3/4-finger gesture service" },
{ "restart", &restart, METH_VARARGS , "stops then starts 3/4-finger gesture service" },
// { "autostart", &autostart, METH_VARARGS , "automatically run on startup (toggleable)" },
{ "buffer", &buffer, METH_VARARGS , "parses output of libinput debug-events" },
{ "help", &help, METH_VARARGS , "shows the help dialog" },
// { "config", &config, METH_VARARGS , "locates the config file " },
{ "debug", &debug, METH_VARARGS , "logs raw output from input events taken from libinput" },
{ NULL, NULL, 0, NULL } // sentinel
};
// create the module configuration
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef module_def =
{
PyModuleDef_HEAD_INIT,
"service",
"Comfortable swipe service",
-1,
methods
};
#endif
PyObject * module;
}
// create the python method signatures
__comfortable_swipe_void_method(status);
__comfortable_swipe_void_method(start);
__comfortable_swipe_void_method(stop);
__comfortable_swipe_void_method(restart);
// __comfortable_swipe_void_method(autostart);
__comfortable_swipe_void_method(buffer);
__comfortable_swipe_void_method(help);
// __comfortable_swipe_void_method(config);
__comfortable_swipe_void_method(debug);
#undef __comfortable_swipe_void_method
// create the method list for C++
static PyMethodDef methods[] =
{
{ "status", &status, METH_VARARGS , "checks status of program, autostart, and config" },
{ "start", &start, METH_VARARGS , "starts 3/4-finger gesture service" },
{ "stop", &stop, METH_VARARGS , "stops 3/4-finger gesture service" },
{ "restart", &restart, METH_VARARGS , "stops then starts 3/4-finger gesture service" },
// { "autostart", &autostart, METH_VARARGS , "automatically run on startup (toggleable)" },
{ "buffer", &buffer, METH_VARARGS , "parses output of libinput debug-events" },
{ "help", &help, METH_VARARGS , "shows the help dialog" },
// { "config", &config, METH_VARARGS , "locates the config file " },
{ "debug", &debug, METH_VARARGS , "logs raw output from input events taken from libinput" },
{ NULL, NULL, 0, NULL } // sentinel
};
// create the module configuration
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef module_def =
{
PyModuleDef_HEAD_INIT,
"service",
"Comfortable swipe service",
-1,
methods
};
#endif
PyObject * module;
}
}
// initialize module
+9 -6
View File
@@ -21,14 +21,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cstdlib> // std::system
namespace comfortable_swipe::service
namespace comfortable_swipe
{
/**
* Debugs output from `libinput debug-events`.
*/
void debug()
namespace service
{
(void) std::system("bash -c \"stdbuf -oL -e0 libinput debug-events 2> >(grep -v 'double tracking')\"");
/**
* Debugs output from `libinput debug-events`.
*/
void debug()
{
(void) std::system("bash -c \"stdbuf -oL -e0 libinput debug-events 2> >(grep -v 'double tracking')\"");
}
}
}
+19 -16
View File
@@ -21,24 +21,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cstdio> // std::puts, std::printf
namespace comfortable_swipe::service
namespace comfortable_swipe
{
/**
* Shows the help window.
*/
void help()
namespace service
{
std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|config|debug|status]");
std::puts("");
std::puts("start - starts 3/4-finger gesture service");
std::puts("stop - stops 3/4-finger gesture service");
std::puts("restart - stops then starts 3/4-finger gesture service");
std::puts("autostart - automatically run on startup (toggleable)");
std::puts("buffer - parses output of libinput debug-events");
std::puts("help - shows the help dialog");
std::puts("config - locates the config file");
std::puts("debug - logs raw output from input events taken from libinput");
std::puts("status - checks status of program and autostart");
/**
* Shows the help window.
*/
void help()
{
std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|config|debug|status]");
std::puts("");
std::puts("start - starts 3/4-finger gesture service");
std::puts("stop - stops 3/4-finger gesture service");
std::puts("restart - stops then starts 3/4-finger gesture service");
std::puts("autostart - automatically run on startup (toggleable)");
std::puts("buffer - parses output of libinput debug-events");
std::puts("help - shows the help dialog");
std::puts("config - locates the config file");
std::puts("debug - logs raw output from input events taken from libinput");
std::puts("status - checks status of program and autostart");
}
}
}
+10 -7
View File
@@ -21,15 +21,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../service/_index.hpp"
namespace comfortable_swipe::service
namespace comfortable_swipe
{
/**
* Restarts the comfortable-swipe service.
*/
void restart()
namespace service
{
comfortable_swipe::service::stop();
comfortable_swipe::service::start();
/**
* Restarts the comfortable-swipe service.
*/
void restart()
{
comfortable_swipe::service::stop();
comfortable_swipe::service::start();
}
}
}
+31 -28
View File
@@ -24,39 +24,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cstdlib> // std::system
#include <unistd.h> // pipe, fork, perror, exit
namespace comfortable_swipe::service
namespace comfortable_swipe
{
/**
* Starts the comfortable-swipe service by buffering libinput debug-events.
* This method is deferred. Please refer to comfortable_swipe::service::buffer()
* for the technical implementation.
*/
void start()
namespace service
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cout.flush();
/**
* Starts the comfortable-swipe service by buffering libinput debug-events.
* This method is deferred. Please refer to comfortable_swipe::service::buffer()
* for the technical implementation.
*/
void start()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cout.flush();
// redirect stdout to stdin
int fd[2];
pipe(fd); // create the pipes
// redirect stdout to stdin
int fd[2];
pipe(fd); // create the pipes
int child;
if ((child = fork()) == -1) {
perror("fork");
exit(EXIT_FAILURE);
int child;
if ((child = fork()) == -1) {
perror("fork");
exit(EXIT_FAILURE);
}
if (child) {
dup2(fd[1], STDOUT_FILENO);
comfortable_swipe::service::debug();
close(fd[0]);
} else {
dup2(fd[0], STDIN_FILENO);
comfortable_swipe::service::buffer();
close(fd[1]);
}
comfortable_swipe::service::stop();
}
if (child) {
dup2(fd[1], STDOUT_FILENO);
comfortable_swipe::service::debug();
close(fd[0]);
} else {
dup2(fd[0], STDIN_FILENO);
comfortable_swipe::service::buffer();
close(fd[1]);
}
comfortable_swipe::service::stop();
}
}
+34 -31
View File
@@ -30,44 +30,47 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
#include <regex> // std::cmatch, std::regex, std::regex_match
namespace comfortable_swipe::service
namespace comfortable_swipe
{
/**
* Prints the status of comfortable-swipe.
*/
void status()
namespace service
{
// std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
// check status of configuration file
try
/**
* Prints the status of comfortable-swipe.
*/
void status()
{
std::puts(COMFORTABLE_SWIPE_CONFIG);
auto config = comfortable_swipe::util::read_config_file(COMFORTABLE_SWIPE_CONFIG);
// print threshold
if (config.count("threshold") > 0)
{
auto & threshold = config["threshold"];
// std::cmatch matches;
// bool ok = (std::regex_match(threshold.data(), matches, std::regex("^\\d+(?:\\.\\d+)??$")) != 0);
// print status of threshold
std::printf(" %9s = %s\n", "threshold", threshold.data()); // ok ? "VALID" : "INVALID"
}
else
std::printf(" %9s is OFF\n", "threshold");
// std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
// print swipe commands
for (auto &command : comfortable_swipe::gesture::swipe_gesture::command_map)
// check status of configuration file
try
{
if (config.count(command) > 0)
std::printf(" %9s = %s\n", command, config[command].data());
std::puts(COMFORTABLE_SWIPE_CONFIG);
auto config = comfortable_swipe::util::read_config_file(COMFORTABLE_SWIPE_CONFIG);
// print threshold
if (config.count("threshold") > 0)
{
auto & threshold = config["threshold"];
// std::cmatch matches;
// bool ok = (std::regex_match(threshold.data(), matches, std::regex("^\\d+(?:\\.\\d+)??$")) != 0);
// print status of threshold
std::printf(" %9s = %s\n", "threshold", threshold.data()); // ok ? "VALID" : "INVALID"
}
else
std::printf(" %9s NOT SET\n", command);
std::printf(" %9s is OFF\n", "threshold");
// print swipe commands
for (auto &command : comfortable_swipe::gesture::swipe_gesture::command_map)
{
if (config.count(command) > 0)
std::printf(" %9s = %s\n", command, config[command].data());
else
std::printf(" %9s NOT SET\n", command);
}
}
catch (const std::runtime_error& e)
{
std::printf("config error: %s\n", e.what());
}
}
catch (const std::runtime_error& e)
{
std::printf("config error: %s\n", e.what());
}
}
}
+30 -27
View File
@@ -29,41 +29,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cstdlib> // std::atoi
#include <cstdio> // FILE, std::feof, std::fgets
namespace comfortable_swipe::service
namespace comfortable_swipe
{
/**
* Stops all comfortable-swipe instances.
*/
void stop()
namespace service
{
// read all service names from process (pgrep)
std::array<char, 128> buffer;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
// make sure pipe exists
if (!pipe)
throw std::runtime_error("stop command failed");
// buffer what to kill
std::string kill = "kill";
// read until end of line
while (!std::feof(pipe.get()))
/**
* Stops all comfortable-swipe instances.
*/
void stop()
{
if (std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL)
// read all service names from process (pgrep)
std::array<char, 128> buffer;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
// make sure pipe exists
if (!pipe)
throw std::runtime_error("stop command failed");
// buffer what to kill
std::string kill = "kill";
// read until end of line
while (!std::feof(pipe.get()))
{
int pid = std::atoi(buffer.data());
if (pid != getpid())
if (std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL)
{
kill += " ";
kill += std::to_string(pid);
int pid = std::atoi(buffer.data());
if (pid != getpid())
{
kill += " ";
kill += std::to_string(pid);
}
}
}
}
// run "kill {pid1} {pid2}..."
(void) std::system(kill.data());
// run "kill {pid1} {pid2}..."
(void) std::system(kill.data());
}
}
}