diff --git a/.gitignore b/.gitignore index 020a973..4a74e57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,42 @@ -# C++ generated headers -*.gch -.out - -# Generated library -comfortable-swipe -libcomfortableswipe.a - # IDE-specific .idea .vscode -# CMake -CMakeLists.txt.user -CMakeCache.txt -CMakeFiles -CMakeScripts -Testing -Makefile -cmake_install.cmake -install_manifest.txt -compile_commands.json -CTestTestfile.cmake -_deps - -# CPack -CPack* +# Build +build/ # Library .lib + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/CHANGELOG b/CHANGELOG index 601e2be..658c069 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,7 @@ v1.1.0 (2020-04-18) * Add `mouse_hold_gestures.cpp` * Bugfix `comfortable-swipe stop` * Bugfix `comfortable-swipe restart` -* Rename `index.hpp` to `all_headers.hpp` +* Rename `index.hpp` to `comfortable_swipe.h` * Rename source directory `lib` to `comfortable_swipe` * Separate `swipe_gesture.cpp` from `keyboard_swipe_gesture.cpp` * Update compiler scripts diff --git a/CMakeLists.txt b/CMakeLists.txt index f6ff232..a3b6608 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,44 +1,61 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.10.2) -# find external libraries here -FIND_LIBRARY(XDO_LIB libxdo) +# HEADER: versions +cmake_minimum_required(VERSION 3.10.2) +project(comfortable-swipe) -# set comfortable swipe version -FILE(STRINGS "VERSION" VERSION) -ADD_DEFINITIONS(-DCOMFORTABLE_SWIPE_VERSION="${VERSION}") +# link external C++ libraries here +find_library(XDO_LIB libxdo.a) -# set project -PROJECT (comfortable-swipe) +# CMAKE variables +set(CMAKE_INSTALL_PREFIX "/home/rico/Git/comfortable-swipe-ubuntu/dist") +set(CMAKE_PROJECT_NAME "comfortable-swipe") +set(CMAKE_PROJECT_DESCRIPTION "3/4-finger comfortableswipe gestures") +# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) -# add our own library -ADD_LIBRARY(comfortableswipe STATIC comfortable_swipe/lib.cpp) +# set flags to use C++ 11 +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED True) +set(CMAKE_CXX_FLAGS_DISTRIBUTION "-O2") -# set our target library output -#SET_TARGET_PROPERTIES(comfortableswipe -# PROPERTIES -# LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/library -#) +# set main directories +set(comfortable_swipe_bin "${CMAKE_CURRENT_BINARY_DIR}/bin") +set(comfortable_swipe_lib "${CMAKE_CURRENT_BINARY_DIR}/lib") +set(comfortable_swipe_share "${CMAKE_CURRENT_BINARY_DIR}/share") +set(comfortable_swipe_include "${CMAKE_CURRENT_BINARY_DIR}/include") -# set our library includes -TARGET_INCLUDE_DIRECTORIES(comfortableswipe - PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/comfortable_swipe" +# set version from VERSION file +file(STRINGS "VERSION" comfortable_swipe_version) + +# set project variables +set(comfortable_swipe_exe_source "${CMAKE_CURRENT_SOURCE_DIR}/comfortable-swipe.cpp") +set(comfortable_swipe_exe_path "${comfortable_swipe_bin}/comfortable-swipe") +set(comfortable_swipe_conf_path "/usr/local/share/comfortable-swipe/comfortable-swipe.conf") + +# C++ definitions +add_definitions( + -DCMAKE_BUILD 1 + -DCOMFORTABLE_SWIPE_VERSION="${comfortable_swipe_version}" + -DCOMFORTABLE_SWIPE_PROGRAM="${comfortable_swipe_exe_path}" + -DCOMFORTABLE_SWIPE_CONFIG="${comfortable_swipe_conf_path}" ) -# add comfortable-swipe command line program -ADD_EXECUTABLE(comfortable-swipe command_line.cpp) +# add our own comfortable-swipe library +add_library(comfortable-swipe.a STATIC "${CMAKE_CURRENT_SOURCE_DIR}/src/comfortable_swipe.cpp") +target_include_directories(comfortable-swipe.a PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") +set_target_properties(comfortable-swipe.a PROPERTIES OUTPUT_NAME "comfortable-swipe") -# link target libraries for program -TARGET_LINK_LIBRARIES(comfortable-swipe comfortableswipe) -TARGET_LINK_LIBRARIES(comfortable-swipe "${XDO_LIB}") +# register comfortable-swipe command line program +add_executable("comfortable-swipe" "${comfortable_swipe_exe_source}") -INSTALL(TARGETS comfortable-swipe - COMPONENT linapp - RUNTIME DESTINATION "/home/rico/cf/run" - LIBRARY DESTINATION "/home/rico/cf/run" - DESTINATION "/home/rico/cf/run" -) +# add libraries to target +target_link_libraries(comfortable-swipe.a "${XDO_LIB}") +target_link_libraries(comfortable-swipe comfortable-swipe.a) +# perform installation +install(TARGETS comfortable-swipe DESTINATION bin) -SET(CPACK_GENERATOR "DEB") -SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "KK") #required -INCLUDE(CPack) +# set platform-specific tasks +set(CPACK_GENERATOR "DEB") +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Rico Tiongson ") #required +include(CPack) diff --git a/command_line.cpp b/comfortable-swipe.cpp similarity index 97% rename from command_line.cpp rename to comfortable-swipe.cpp index 934f666..1a79db1 100644 --- a/command_line.cpp +++ b/comfortable-swipe.cpp @@ -16,10 +16,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "comfortable_swipe/lib.cpp" #include // std::ios #include // std::cin, std::cout, std::cerr #include // std::string +#include "src/comfortable_swipe.cpp" /* Command-line function. */ diff --git a/install b/install index 81af670..a165536 100755 --- a/install +++ b/install @@ -8,7 +8,7 @@ function install { local program="comfortable-swipe" local program_exe="/usr/local/bin/$program" local compile_command="$dir/cpp.compile.sh" - local compile_target="$dir/command_line.cpp" + local compile_target="$dir/comfortable-swipe.cpp" local conf_path="/usr/local/share/$program/$program.conf" local dconf_path="$dir/defaults.conf" local old_conf_path="${XDG_CONFIG_HOME:-$HOME/.config}/$program.conf" diff --git a/comfortable_swipe/lib.cpp b/src/comfortable_swipe.cpp similarity index 92% rename from comfortable_swipe/lib.cpp rename to src/comfortable_swipe.cpp index 4854836..c93db77 100644 --- a/comfortable_swipe/lib.cpp +++ b/src/comfortable_swipe.cpp @@ -1,3 +1,7 @@ +/** + * Add all cpp implementation files are registered here. + */ + #ifndef __COMFORTABLE_SWIPE__ #define __COMFORTABLE_SWIPE__ @@ -19,13 +23,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "all_headers.hpp" +#include "comfortable_swipe.h" -/** - * Add all cpp files below to be ready for export. - */ - -#include "driver.cpp" #include "gesture/keyboard_swipe_gesture.cpp" #include "gesture/mouse_hold_gesture.cpp" #include "gesture/swipe_gesture.cpp" @@ -43,5 +42,6 @@ along with this program. If not, see . #include "util/autostart_filename.cpp" #include "util/conf_filename.cpp" #include "util/read_config_file.cpp" +#include "start.cpp" #endif /* __COMFORTABLE_SWIPE__ */ diff --git a/comfortable_swipe/all_headers.hpp b/src/comfortable_swipe.h similarity index 77% rename from comfortable_swipe/all_headers.hpp rename to src/comfortable_swipe.h index 19d74ec..a5300ab 100644 --- a/comfortable_swipe/all_headers.hpp +++ b/src/comfortable_swipe.h @@ -2,11 +2,11 @@ * Add header files will be imported here. * You can import this as a shorthand: * - * #include "../all_headers.hpp" + * #include "comfortable_swipe.h" */ -#ifndef __COMFORTABLE_SWIPE__all_headers_hpp__ -#define __COMFORTABLE_SWIPE__all_headers_hpp__ +#ifndef __COMFORTABLE_SWIPE__comfortable_swipe_h__ +#define __COMFORTABLE_SWIPE__comfortable_swipe_h__ /* Comfortable Swipe @@ -27,14 +27,14 @@ along with this program. If not, see . */ // global defines -#ifndef __COMFORTABLE_SWIPE__PROGRAM__ -#define __COMFORTABLE_SWIPE__PROGRAM__ "/usr/local/bin/comfortable-swipe" -#endif /* __COMFORTABLE_SWIPE__PROGRAM__ */ +#ifndef COMFORTABLE_SWIPE_PROGRAM +#define COMFORTABLE_SWIPE_PROGRAM "/usr/local/bin/comfortable-swipe" +#endif /* COMFORTABLE_SWIPE_PROGRAM */ -#ifndef __COMFORTABLE_SWIPE__CONFIG__ -#define __COMFORTABLE_SWIPE__CONFIG__ \ +#ifndef COMFORTABLE_SWIPE_CONFIG +#define COMFORTABLE_SWIPE_CONFIG \ "/usr/local/share/comfortable-swipe/comfortable-swipe.conf" -#endif /* __COMFORTABLE_SWIPE__CONFIG__ */ +#endif /* COMFORTABLE_SWIPE_CONFIG */ #ifndef COMFORTABLE_SWIPE_VERSION #warning COMFORTABLE_SWIPE_VERSION is not defined @@ -46,8 +46,6 @@ along with this program. If not, see . extern "C" { namespace comfortable_swipe { -// driver method -int driver(); // this is found in the util/ folder namespace util { const char *autostart_filename(); @@ -74,5 +72,6 @@ void stop(); #include "gesture/mouse_hold_gesture.h" #include "gesture/swipe_gesture.h" #include "gesture/xdo_gesture.h" +#include "start.h" -#endif /* __COMFORTABLE_SWIPE__all_headers_hpp__ */ +#endif /* __COMFORTABLE_SWIPE__comfortable_swipe_h__ */ diff --git a/comfortable_swipe/gesture/keyboard_swipe_gesture.cpp b/src/gesture/keyboard_swipe_gesture.cpp similarity index 100% rename from comfortable_swipe/gesture/keyboard_swipe_gesture.cpp rename to src/gesture/keyboard_swipe_gesture.cpp diff --git a/comfortable_swipe/gesture/keyboard_swipe_gesture.h b/src/gesture/keyboard_swipe_gesture.h similarity index 100% rename from comfortable_swipe/gesture/keyboard_swipe_gesture.h rename to src/gesture/keyboard_swipe_gesture.h diff --git a/comfortable_swipe/gesture/mouse_hold_gesture.cpp b/src/gesture/mouse_hold_gesture.cpp similarity index 100% rename from comfortable_swipe/gesture/mouse_hold_gesture.cpp rename to src/gesture/mouse_hold_gesture.cpp diff --git a/comfortable_swipe/gesture/mouse_hold_gesture.h b/src/gesture/mouse_hold_gesture.h similarity index 100% rename from comfortable_swipe/gesture/mouse_hold_gesture.h rename to src/gesture/mouse_hold_gesture.h diff --git a/comfortable_swipe/gesture/swipe_gesture.cpp b/src/gesture/swipe_gesture.cpp similarity index 100% rename from comfortable_swipe/gesture/swipe_gesture.cpp rename to src/gesture/swipe_gesture.cpp diff --git a/comfortable_swipe/gesture/swipe_gesture.h b/src/gesture/swipe_gesture.h similarity index 100% rename from comfortable_swipe/gesture/swipe_gesture.h rename to src/gesture/swipe_gesture.h diff --git a/comfortable_swipe/gesture/swipe_gesture.regex.cpp b/src/gesture/swipe_gesture.regex.cpp similarity index 100% rename from comfortable_swipe/gesture/swipe_gesture.regex.cpp rename to src/gesture/swipe_gesture.regex.cpp diff --git a/comfortable_swipe/gesture/xdo_gesture.cpp b/src/gesture/xdo_gesture.cpp similarity index 100% rename from comfortable_swipe/gesture/xdo_gesture.cpp rename to src/gesture/xdo_gesture.cpp diff --git a/comfortable_swipe/gesture/xdo_gesture.h b/src/gesture/xdo_gesture.h similarity index 100% rename from comfortable_swipe/gesture/xdo_gesture.h rename to src/gesture/xdo_gesture.h diff --git a/comfortable_swipe/service/autostart.cpp b/src/service/autostart.cpp similarity index 95% rename from comfortable_swipe/service/autostart.cpp rename to src/service/autostart.cpp index 6a10d07..c726094 100644 --- a/comfortable_swipe/service/autostart.cpp +++ b/src/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 "../all_headers.hpp" +#include "../comfortable_swipe.h" #include // std::remove #include // std::system #include // std::ifstream, std::ofstream @@ -51,7 +51,7 @@ void autostart() { else { fout << "[Desktop Entry]\n" "Type=Application\n" - "Exec=bash -c \"" __COMFORTABLE_SWIPE__PROGRAM__ " start\"\n" + "Exec=bash -c \"" COMFORTABLE_SWIPE_PROGRAM " start\"\n" "Hidden=false\n" "NoDisplay=false\n" "X-GNOME-Autostart-enabled=true\n" diff --git a/comfortable_swipe/service/buffer.cpp b/src/service/buffer.cpp similarity index 88% rename from comfortable_swipe/service/buffer.cpp rename to src/service/buffer.cpp index 6094390..fbacee6 100644 --- a/comfortable_swipe/service/buffer.cpp +++ b/src/service/buffer.cpp @@ -19,14 +19,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "../all_headers.hpp" -#include // std::exit +#include "../start.h" /** * Starts the comfortable-swipe service by buffering libinput debug-events. */ namespace comfortable_swipe::service { -void buffer() { std::exit(comfortable_swipe::driver()); } +void buffer() { comfortable_swipe::start(); } } // namespace comfortable_swipe::service #endif /* __COMFORTABLE_SWIPE__service_buffer__ */ diff --git a/comfortable_swipe/service/config.cpp b/src/service/config.cpp similarity index 97% rename from comfortable_swipe/service/config.cpp rename to src/service/config.cpp index 0363793..4fc42d1 100644 --- a/comfortable_swipe/service/config.cpp +++ b/src/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 "../all_headers.hpp" +#include "../comfortable_swipe.h" #include // std::puts namespace comfortable_swipe::service { diff --git a/comfortable_swipe/service/debug.cpp b/src/service/debug.cpp similarity index 100% rename from comfortable_swipe/service/debug.cpp rename to src/service/debug.cpp diff --git a/comfortable_swipe/service/help.cpp b/src/service/help.cpp similarity index 98% rename from comfortable_swipe/service/help.cpp rename to src/service/help.cpp index 47f76e6..638ceb2 100644 --- a/comfortable_swipe/service/help.cpp +++ b/src/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 "../all_headers.hpp" +#include "../comfortable_swipe.h" #include // std::puts, std::printf namespace comfortable_swipe::service { diff --git a/comfortable_swipe/service/restart.cpp b/src/service/restart.cpp similarity index 97% rename from comfortable_swipe/service/restart.cpp rename to src/service/restart.cpp index 8485707..6336adf 100644 --- a/comfortable_swipe/service/restart.cpp +++ b/src/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 "../all_headers.hpp" +#include "../comfortable_swipe.h" #include // freopen, stdout namespace comfortable_swipe::service { diff --git a/comfortable_swipe/service/start.cpp b/src/service/start.cpp similarity index 87% rename from comfortable_swipe/service/start.cpp rename to src/service/start.cpp index 6505284..6bcb02d 100644 --- a/comfortable_swipe/service/start.cpp +++ b/src/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 "../all_headers.hpp" +#include "../comfortable_swipe.h" #include // std::system namespace comfortable_swipe::service { @@ -29,8 +29,8 @@ namespace comfortable_swipe::service { * for the technical implementation. */ void start() { - (void)std::system(__COMFORTABLE_SWIPE__PROGRAM__ - " debug | " __COMFORTABLE_SWIPE__PROGRAM__ " buffer"); + (void)std::system(COMFORTABLE_SWIPE_PROGRAM + " debug | " COMFORTABLE_SWIPE_PROGRAM " buffer"); } } // namespace comfortable_swipe::service diff --git a/comfortable_swipe/service/status.cpp b/src/service/status.cpp similarity index 99% rename from comfortable_swipe/service/status.cpp rename to src/service/status.cpp index 877e315..5c426b8 100644 --- a/comfortable_swipe/service/status.cpp +++ b/src/service/status.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 "../all_headers.hpp" +#include "../comfortable_swipe.h" #include // std::array #include // FILE, std::feof, std::fgets, std::printf #include // std::atoi diff --git a/comfortable_swipe/service/stop.cpp b/src/service/stop.cpp similarity index 100% rename from comfortable_swipe/service/stop.cpp rename to src/service/stop.cpp diff --git a/comfortable_swipe/driver.cpp b/src/start.cpp similarity index 63% rename from comfortable_swipe/driver.cpp rename to src/start.cpp index 0c3d4cf..0eb9290 100644 --- a/comfortable_swipe/driver.cpp +++ b/src/start.cpp @@ -1,5 +1,5 @@ -#ifndef __COMFORTABLE_SWIPE__driver__ -#define __COMFORTABLE_SWIPE__driver__ +#ifndef __COMFORTABLE_SWIPE__start__ +#define __COMFORTABLE_SWIPE__start__ /* Comfortable Swipe @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "all_headers.hpp" +#include "comfortable_swipe.h" #include // fgets_unlocked, stdin #include // std::ios, std::cout, std::cin @@ -27,7 +27,7 @@ along with this program. If not, see . * The main driver program. */ namespace comfortable_swipe { -int driver() { +void start() { // unsync for faster IO std::ios::sync_with_stdio(false); std::cin.tie(0); @@ -45,15 +45,31 @@ int driver() { // hold3=button1 hold button 1 on 3 fingers // hold4=button3 hold button 3 (right click) on 3 fingers // hold3=ignore - comfortable_swipe::gesture::mouse_hold_gesture mouse_hold( - config["hold3"].c_str(), config["hold4"].c_str()); + const char * const hold3 = config["hold3"].c_str(); + const char * const hold4 = config["hold4"].c_str(); + comfortable_swipe::gesture::mouse_hold_gesture mouse_hold(hold3, hold4); // initialize keyboard swipe gesture handler + const float threshold = config.count("threshold") ? std::stof(config["threshold"]) : 0.0; + const char * const left3 = config["left3"].c_str(); + const char * const left4 = config["left4"].c_str(); + const char * const right3 = config["right3"].c_str(); + const char * const right4 = config["right4"].c_str(); + const char * const up3 = config["up3"].c_str(); + const char * const up4 = config["up4"].c_str(); + const char * const down3 = config["down3"].c_str(); + const char * const down4 = config["down4"].c_str(); comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe( - config.count("threshold") ? std::stof(config["threshold"]) : 0.0, - config["left3"].c_str(), config["left4"].c_str(), - config["right3"].c_str(), config["right4"].c_str(), config["up3"].c_str(), - config["up4"].c_str(), config["down3"].c_str(), config["down4"].c_str()); + threshold, + left3, + left4, + right3, + right4, + up3, + up4, + down3, + down4 + ); // prepare data containers std::array line; @@ -62,16 +78,13 @@ int driver() { while (fgets_unlocked(line.data(), line.size(), stdin) != NULL) { // prioritize mouse hold gesture first mouse_hold.parse_line(line.data()); - - // if mouse hold fails, try keyboard hold if (!mouse_hold.is_mousedown()) { - // attempt to parse keyboard gestures + // if mouse hold fails, try keyboard swipe + // attempt to parse keyboard gestures with the same line data keyboard_swipe.parse_line(line.data()); } } - - return 0; } } // namespace comfortable_swipe -#endif /* __COMFORTABLE_SWIPE__driver__ */ +#endif /* __COMFORTABLE_SWIPE__start__ */ diff --git a/src/start.h b/src/start.h new file mode 100644 index 0000000..f9c324e --- /dev/null +++ b/src/start.h @@ -0,0 +1,8 @@ +#ifndef __COMFORTABLE_SWIPE__start_h__ +#define __COMFORTABLE_SWIPE__start_h__ + +namespace comfortable_swipe { + void start(); +} + +#endif /* __COMFORTABLE_SWIPE__start_h__ */ diff --git a/comfortable_swipe/util/autostart_filename.cpp b/src/util/autostart_filename.cpp similarity index 100% rename from comfortable_swipe/util/autostart_filename.cpp rename to src/util/autostart_filename.cpp diff --git a/comfortable_swipe/util/conf_filename.cpp b/src/util/conf_filename.cpp similarity index 89% rename from comfortable_swipe/util/conf_filename.cpp rename to src/util/conf_filename.cpp index 250a9e7..e2f42ab 100644 --- a/comfortable_swipe/util/conf_filename.cpp +++ b/src/util/conf_filename.cpp @@ -19,13 +19,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "../all_headers.hpp" +#include "../comfortable_swipe.h" namespace comfortable_swipe::util { /** * The path where the configuration file is located. */ -constexpr const char *conf_filename() { return __COMFORTABLE_SWIPE__CONFIG__; } +constexpr const char *conf_filename() { return COMFORTABLE_SWIPE_CONFIG; } } // namespace comfortable_swipe::util #endif /* __COMFORTABLE_SWIPE__util_conf_filename__ */ diff --git a/comfortable_swipe/util/read_config_file.cpp b/src/util/read_config_file.cpp similarity index 100% rename from comfortable_swipe/util/read_config_file.cpp rename to src/util/read_config_file.cpp