diff --git a/.gitignore b/.gitignore index c6cf9bf..05bf491 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ downloads/ eggs/ .eggs/ lib/ +!/lib lib64/ parts/ sdist/ diff --git a/lib/_index.cpp b/lib/_index.cpp new file mode 100644 index 0000000..e274cfb --- /dev/null +++ b/lib/_index.cpp @@ -0,0 +1,8 @@ +#ifndef __COMFORTABLE_SWIPE__index_cpp__ +#define __COMFORTABLE_SWIPE__index_cpp__ + +#include "gesture/_index.cpp" +#include "service/_index.cpp" +#include "util/_index.cpp" + +#endif /* __COMFORTABLE_SWIPE__index_cpp__ */ diff --git a/lib/_index.hpp b/lib/_index.hpp new file mode 100644 index 0000000..ce0849d --- /dev/null +++ b/lib/_index.hpp @@ -0,0 +1,8 @@ +#ifndef __COMFORTABLE_SWIPE__index_hpp__ +#define __COMFORTABLE_SWIPE__index_hpp__ + +#include "gesture/_index.hpp" +#include "service/_index.hpp" +#include "util/_index.hpp" + +#endif /* __COMFORTABLE_SWIPE__index_hpp__ */ diff --git a/lib/_macro.cpp b/lib/_macro.cpp new file mode 100644 index 0000000..494442a --- /dev/null +++ b/lib/_macro.cpp @@ -0,0 +1,12 @@ +#ifndef __COMFORTABLE_SWIPE__macro_hpp__ +#define __COMFORTABLE_SWIPE__macro_hpp__ + +#ifndef __COMFORTABLE_SWIPE__CONFIG__ +#define __COMFORTABLE_SWIPE__CONFIG__ "/usr/local/share/comfortable-swipe/comfortable-swipe.conf" +#endif /* __COMFORTABLE_SWIPE__CONFIG__ */ + +#ifndef __COMFORTABLE_SWIPE__VERSION__ +#warning __COMFORTABLE_SWIPE__VERSION__ "must be defined." +#endif /* __COMFORTABLE_SWIPE__VERSION__ */ + +#endif /* __COMFORTABLE_SWIPE__macro_hpp__ */ diff --git a/lib/_python.cpp b/lib/_python.cpp new file mode 100644 index 0000000..fcddd3e --- /dev/null +++ b/lib/_python.cpp @@ -0,0 +1,8 @@ +#ifndef __COMFORTABLE_SWIPE__python_cpp__ +#define __COMFORTABLE_SWIPE__python_cpp__ + +#include "service/_python.cpp" +#include "util/_python.cpp" +#include "comfortable-swipe.cpp" + +#endif /* __COMFORTABLE_SWIPE__python_cpp__ */ diff --git a/lib/comfortable-swipe b/lib/comfortable-swipe new file mode 100644 index 0000000..6465c73 --- /dev/null +++ b/lib/comfortable-swipe @@ -0,0 +1 @@ +#include "comfortable-swipe.cpp" diff --git a/lib/comfortable-swipe.cpp b/lib/comfortable-swipe.cpp new file mode 100644 index 0000000..1f10dd1 --- /dev/null +++ b/lib/comfortable-swipe.cpp @@ -0,0 +1,26 @@ +#ifndef __COMFORTABLE_SWIPE__ +#define __COMFORTABLE_SWIPE__ + +/* +Comfortable Swipe +by Rico Tiongson + +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 . +*/ + +#include "_macro.cpp" +#include "_index.hpp" +#include "_index.cpp" + +#endif /* __COMFORTABLE_SWIPE__ */ diff --git a/lib/gesture/_index.cpp b/lib/gesture/_index.cpp new file mode 100644 index 0000000..5de8bb2 --- /dev/null +++ b/lib/gesture/_index.cpp @@ -0,0 +1,9 @@ +#ifndef __COMFORTABLE_SWIPE__gesture_index_cpp__ +#define __COMFORTABLE_SWIPE__gesture_index_cpp__ + +#include "_index.hpp" +#include "xdo_gesture.cpp" +#include "swipe_gesture.cpp" +#include "swipe_gesture.regex.cpp" + +#endif /* __COMFORTABLE_SWIPE__gesture_index_cpp__ */ diff --git a/lib/gesture/_index.hpp b/lib/gesture/_index.hpp new file mode 100644 index 0000000..9c097c5 --- /dev/null +++ b/lib/gesture/_index.hpp @@ -0,0 +1,7 @@ +#ifndef __COMFORTABLE_SWIPE__gesture_index_hpp__ +#define __COMFORTABLE_SWIPE__gesture_index_hpp__ + +#include "xdo_gesture.h" +#include "swipe_gesture.h" + +#endif /* __COMFORTABLE_SWIPE__gesture_index_hpp__ */ diff --git a/lib/service/_index.cpp b/lib/service/_index.cpp new file mode 100644 index 0000000..94a6fb5 --- /dev/null +++ b/lib/service/_index.cpp @@ -0,0 +1,15 @@ +#ifndef __COMFORTABLE_SWIPE__service_index_cpp__ +#define __COMFORTABLE_SWIPE__service_index_cpp__ + +#include "_index.hpp" +#include "autostart.cpp" +#include "buffer.cpp" +#include "config.cpp" +#include "debug.cpp" +#include "help.cpp" +#include "restart.cpp" +#include "start.cpp" +#include "status.cpp" +#include "stop.cpp" + +#endif /* __COMFORTABLE_SWIPE__service_index_cpp__ */ diff --git a/lib/service/_index.hpp b/lib/service/_index.hpp new file mode 100644 index 0000000..2ff0052 --- /dev/null +++ b/lib/service/_index.hpp @@ -0,0 +1,26 @@ +#ifndef __COMFORTABLE_SWIPE__service_index_hpp__ +#define __COMFORTABLE_SWIPE__service_index_hpp__ + +#include // std::map +#include // std::string + +extern "C" +{ + namespace comfortable_swipe + { + namespace service + { + void autostart(); + void buffer(); + void config(); + void debug(); + void help(); + void restart(); + void start(); + void stop(); + void status(); + } + } +} + +#endif /* __COMFORTABLE_SWIPE__service_index_hpp__ */ diff --git a/lib/service/_python.cpp b/lib/service/_python.cpp new file mode 100644 index 0000000..e44e0f0 --- /dev/null +++ b/lib/service/_python.cpp @@ -0,0 +1,82 @@ +#ifndef __COMFORTABLE_SWIPE__service_python__ +#define __COMFORTABLE_SWIPE__service_python__ + +#include "_index.hpp" +#include + +// export as python module +namespace comfortable_swipe::service::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; +} + +// initialize module +#if PY_MAJOR_VERSION >= 3 + PyMODINIT_FUNC + PyInit_service(void) + { + using comfortable_swipe::service::python::module_def; + using comfortable_swipe::service::python::module; + if (module != NULL) return module; + return module = PyModule_Create(&module_def); + } +#else /* PY_MAJOR_VERSION < 3 */ + PyMODINIT_FUNC + initservice(void) + { + using comfortable_swipe::service::python::methods; + using comfortable_swipe::service::python::module; + if (module != NULL) return; + module = Py_InitModule("service", methods); + } +#endif /* PY_MAJOR_VERSION */ + +#endif /* __COMFORTABLE_SWIPE__service_python__ */ diff --git a/lib/service/autostart.cpp b/lib/service/autostart.cpp index ab96e56..cbfe79b 100644 --- a/lib/service/autostart.cpp +++ b/lib/service/autostart.cpp @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "../util/__index__.hpp" +#include "../util/_index.hpp" #include // std::cerr, std::cout, std::endl #include // std::ifstream, std::ofstream #include // std::string diff --git a/lib/service/buffer.cpp b/lib/service/buffer.cpp index e183111..e89cd4d 100644 --- a/lib/service/buffer.cpp +++ b/lib/service/buffer.cpp @@ -19,8 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "../util/__index__.hpp" -#include "../gesture/__index__.hpp" +#include "../util/_index.hpp" +#include "../gesture/_index.hpp" #include // fgets_unlocked, stdin /** diff --git a/lib/service/config.cpp b/lib/service/config.cpp index db2cff5..f7d3d6c 100644 --- a/lib/service/config.cpp +++ b/lib/service/config.cpp @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "../util/__index__.hpp" +#include "../util/_index.hpp" #include // std::puts namespace comfortable_swipe::service diff --git a/lib/service/help.cpp b/lib/service/help.cpp index b4f94be..0f30bf3 100644 --- a/lib/service/help.cpp +++ b/lib/service/help.cpp @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "../util/__index__.hpp" +#include "../util/_index.hpp" #include // std::puts, std::printf namespace comfortable_swipe::service diff --git a/lib/service/restart.cpp b/lib/service/restart.cpp index f4348f4..b66beb1 100644 --- a/lib/service/restart.cpp +++ b/lib/service/restart.cpp @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "../service/__index__.hpp" +#include "../service/_index.hpp" namespace comfortable_swipe::service { diff --git a/lib/service/start.cpp b/lib/service/start.cpp index a85e34a..b0b1cbd 100644 --- a/lib/service/start.cpp +++ b/lib/service/start.cpp @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "__index__.hpp" +#include "_index.hpp" #include // std::system #include // pipe, fork, perror, exit diff --git a/lib/service/status.cpp b/lib/service/status.cpp index 0eb3be5..906565d 100644 --- a/lib/service/status.cpp +++ b/lib/service/status.cpp @@ -19,8 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "../util/__index__.hpp" -#include "../gesture/__index__.hpp" +#include "../util/_index.hpp" +#include "../gesture/_index.hpp" #include // std::runtime_error #include // popen, pclose, getpid, access, F_OK #include // std::unique_ptr diff --git a/lib/util/_index.cpp b/lib/util/_index.cpp new file mode 100644 index 0000000..8320ce7 --- /dev/null +++ b/lib/util/_index.cpp @@ -0,0 +1,9 @@ +#ifndef __COMFORTABLE_SWIPE__util_index_cpp__ +#define __COMFORTABLE_SWIPE__util_index_cpp__ + +#include "_index.hpp" +#include "autostart_filename.cpp" +#include "conf_filename.cpp" +#include "read_config_file.cpp" + +#endif /* __COMFORTABLE_SWIPE__util_index_cpp__ */ diff --git a/lib/util/_index.hpp b/lib/util/_index.hpp new file mode 100644 index 0000000..3a7f138 --- /dev/null +++ b/lib/util/_index.hpp @@ -0,0 +1,20 @@ +#ifndef __COMFORTABLE_SWIPE__util_index_hpp__ +#define __COMFORTABLE_SWIPE__util_index_hpp__ + +#include // std::map +#include // std::string + +extern "C" +{ + namespace comfortable_swipe + { + namespace util + { + const char* autostart_filename(); + constexpr const char* conf_filename(); + std::map read_config_file(const char*); + } + } +} + +#endif /* __COMFORTABLE_SWIPE__util_index_hpp__ */ diff --git a/lib/util/_python.cpp b/lib/util/_python.cpp new file mode 100644 index 0000000..6d845d5 --- /dev/null +++ b/lib/util/_python.cpp @@ -0,0 +1,70 @@ +#ifndef __COMFORTABLE_SWIPE__util_python__ +#define __COMFORTABLE_SWIPE__util_python__ + +#include "_index.hpp" +#include + +// export as python module +namespace comfortable_swipe::util::python +{ + // create the python method signatures + static PyObject * + autostart_filename(PyObject * self, PyObject * args) + { + return Py_BuildValue("s", comfortable_swipe::util::autostart_filename()); + } + + static PyObject * + conf_filename(PyObject * self, PyObject * args) + { + return Py_BuildValue("s", comfortable_swipe::util::conf_filename); + } + + + #undef __comfortable_swipe_void_method + + // create the method list for C++ + static PyMethodDef methods[] = + { + { "autostart_filename", &autostart_filename, METH_VARARGS, "the location of the autostart file" }, + { "conf_filename", &conf_filename, METH_VARARGS, "the location of the configuration file" }, + { NULL, NULL, 0, NULL } // sentinel + }; + + // create the module configuration + #if PY_MAJOR_VERSION >= 3 + static struct PyModuleDef module_def = + { + PyModuleDef_HEAD_INIT, + "util", + "Comfortable swipe utility", + -1, + methods + }; + #endif + + PyObject * module; +} + +// initialize module +#if PY_MAJOR_VERSION >= 3 + PyMODINIT_FUNC + PyInit_util(void) + { + using comfortable_swipe::util::python::module_def; + using comfortable_swipe::util::python::module; + if (module != NULL) return module; + return module = PyModule_Create(&module_def); + } +#else /* PY_MAJOR_VERSION < 3 */ + PyMODINIT_FUNC + initutil(void) + { + using comfortable_swipe::util::python::methods; + using comfortable_swipe::util::python::module; + if (module != NULL) return; + module = Py_InitModule("util", methods); + } +#endif /* PY_MAJOR_VERSION */ + +#endif /* __COMFORTABLE_SWIPE__util_python__ */ diff --git a/setup.py b/setup.py index 6d7f754..dd3a6bd 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ try: extensions = [Extension( name='{}.{}'.format(PYTHON_NAME, extension_name), define_macros=list(cpp_macros.items()), - sources=[os.path.join(__DIR__, 'lib', '__python__.cpp')], + sources=[os.path.join(__DIR__, 'lib', '_python.cpp')], extra_compile_args=['-O2', '-Wno-unused-result'], libraries=['xdo'] ) for extension_name in extension_names]