Compare commits

...

6 Commits

Author SHA1 Message Date
Rico Tiongson
f2c731eb1b Update CMakeLists data 2020-04-18 16:20:23 +08:00
Rico Tiongson
69c4649f04 Delete generated binary 2020-04-18 15:31:03 +08:00
Rico Tiongson
f2893e4aaa Update CMakeLists 2020-04-18 15:30:21 +08:00
Rico Tiongson
7d897ac09e Apply clang-format to source files 2020-04-18 14:41:22 +08:00
Rico Tiongson
fb92169a16 Reformat directory structure 2020-04-18 14:40:13 +08:00
Rico Tiongson
2e91ac17fd Prepare values for CMakeLists.txt 2020-04-18 07:20:53 +08:00
35 changed files with 418 additions and 299 deletions

57
.gitignore vendored
View File

@ -1,6 +1,57 @@
# C++ generated headers
*.gch
# IDE-specific # IDE-specific
.idea .idea
.vscode .vscode
# Generated binary
/comfortable-swipe
/build
# CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
*.cmake
# 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

View File

@ -7,7 +7,7 @@ v1.1.0 (2020-04-18)
* Add `mouse_hold_gestures.cpp` * Add `mouse_hold_gestures.cpp`
* Bugfix `comfortable-swipe stop` * Bugfix `comfortable-swipe stop`
* Bugfix `comfortable-swipe restart` * 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` * Rename source directory `lib` to `comfortable_swipe`
* Separate `swipe_gesture.cpp` from `keyboard_swipe_gesture.cpp` * Separate `swipe_gesture.cpp` from `keyboard_swipe_gesture.cpp`
* Update compiler scripts * Update compiler scripts

58
CMakeLists.txt Normal file
View File

@ -0,0 +1,58 @@
# Run with: cmake . && make && make install
cmake_minimum_required(VERSION 3.10.2)
project(comfortable-swipe)
set(CMAKE_PROJECT_NAME "Comfortable Swipe")
set(CMAKE_PROJECT_DESCRIPTION "Comfortable 3/4-finger swipe gestures")
# set flags to use C++ 11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS_DISTRIBUTION "-O2")
# set main directories
set(comfortable_swipe_bin "${CMAKE_INSTALL_PREFIX}/bin")
set(comfortable_swipe_lib "${CMAKE_INSTALL_PREFIX}/lib")
set(comfortable_swipe_share "${CMAKE_INSTALL_PREFIX}/share")
set(comfortable_swipe_include "${CMAKE_INSTALL_PREFIX}/include")
# set version from VERSION file
file(STRINGS "VERSION" comfortable_swipe_version)
# set project variables
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(
-DCOMFORTABLE_SWIPE_VERSION="${comfortable_swipe_version}"
-DCOMFORTABLE_SWIPE_PROGRAM="${comfortable_swipe_exe_path}"
-DCOMFORTABLE_SWIPE_CONFIG="${comfortable_swipe_conf_path}"
)
# add our build-time only static library
add_library(comfortable-swipe.lib STATIC "src/comfortable_swipe.cpp")
target_include_directories(comfortable-swipe.lib PUBLIC "src")
# register comfortable-swipe command line program
add_executable("comfortable-swipe" "comfortable-swipe.cpp")
# link libraries here
find_library(XDO libxdo.so)
target_link_libraries(comfortable-swipe.lib "${XDO}")
target_link_libraries(comfortable-swipe comfortable-swipe.lib)
# perform installation
install(TARGETS comfortable-swipe DESTINATION bin)
# set where .desktop file should be installed
if (DEFINED ENV{XDG_CONFIG_HOME})
set (comfortable_swipe_desktop "$ENV{XDG_CONFIG_HOME}/autostart/")
else()
set(comfortable_swipe_desktop "$ENV{HOME}/.config/autostart/")
endif()
install(FILES "share/comfortable-swipe.desktop" DESTINATION "${comfortable_swipe_desktop}")
# set platform-specific info
include(cmake/cpack.cmake)

View File

@ -16,10 +16,15 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "comfortable_swipe/lib"
#include <ios> // std::ios #include <ios> // std::ios
#include <iostream> // std::cin, std::cout, std::cerr #include <iostream> // std::cin, std::cout, std::cerr
#include <string> // std::string #include <string> // std::string
#include "src/comfortable_swipe.h" // comfortable_swipe
// make sure implementation is also imported
#ifndef __COMFORTABLE_SWIPE__
#include "src/comfortable_swipe.cpp"
#endif
/* Command-line function. */ /* Command-line function. */

View File

@ -1,84 +0,0 @@
#ifndef __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__
#define __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "swipe_gesture.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace comfortable_swipe::gesture
{
class keyboard_swipe_gesture : public swipe_gesture
{
public:
// constructor
keyboard_swipe_gesture(
const float threshold,
const char* left3 /* 000 */,
const char* left4 /* 001 */,
const char* right3 /* 010 */,
const char* right4 /* 011 */,
const char* up3 /* 100 */,
const char* up4 /* 101 */,
const char* down3 /* 110 */,
const char* down4 /* 111 */
);
// destructor
virtual ~keyboard_swipe_gesture();
// hooks that we override
virtual void begin() override;
virtual void update() override;
virtual void end() override;
// override this when keyboard gesture is to be performed
virtual void do_keyboard_gesture(int mask);
protected:
// stores square of threshold so we can compute faster
float threshold_squared;
// stores previous gesture so we don't repeat action
int previous_gesture;
// stores all command strings for xdo to execute
const char ** commands;
public:
// static enums we will use for gesture matching
static const int FRESH;
static const int MSK_THREE_FINGERS;
static const int MSK_FOUR_FINGERS;
static const int MSK_NEGATIVE;
static const int MSK_POSITIVE;
static const int MSK_HORIZONTAL;
static const int MSK_VERTICAL;
static const char * const command_map[8];
};
}
#ifdef __cplusplus
}
#endif
#endif /* __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__ */

View File

@ -1,71 +0,0 @@
#ifndef __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__
#define __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "swipe_gesture.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace comfortable_swipe::gesture
{
class mouse_hold_gesture : public swipe_gesture
{
public:
// constructor
mouse_hold_gesture(
const char* hold3, // 3 finger mouse down
const char* hold4 // 4 finger mouse down
);
// the button being clicked
int button;
virtual ~mouse_hold_gesture();
// override begin and end for mousedown
virtual void begin() override;
virtual void update() override;
virtual void end() override;
// provide our own mouse functions
virtual void do_mousedown(const char*);
virtual void do_mouseup(const char*);
virtual bool is_mousedown() const;
// utility method to parse mouse input given config characters
static int parse_mouse_button(const char*);
protected:
// command holders
const char * hold3;
const char * hold4;
// flag we can use to check if mouse is down
bool flag_mousedown;
};
}
#ifdef __cplusplus
}
#endif
#endif /* __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__ */

View File

@ -1,73 +0,0 @@
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "xdo_gesture.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace comfortable_swipe::gesture
{
class swipe_gesture : public xdo_gesture
{
public:
// constructor
swipe_gesture();
// destructor
virtual ~swipe_gesture();
// fields for xdo
int fingers;
// normal values (for touchpad mapping)
float x, y, dx, dy;
// unaccelerated values (for screen mapping)
float ux, uy, udx, udy;
// hooks that we can override (mark as virtual)
virtual void begin();
virtual void update();
virtual void end();
virtual bool parse_line(const char *);
protected:
// location of mouse
int screen_num, ix, iy;
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
bool flag_swiping;
public:
// regex patterns
static const char* GESTURE_BEGIN_REGEX_PATTERN;
static const char* GESTURE_UPDATE_REGEX_PATTERN;
static const char* GESTURE_END_REGEX_PATTERN;
};
}
#ifdef __cplusplus
}
#endif
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__ */

View File

@ -8,7 +8,7 @@ function install {
local program="comfortable-swipe" local program="comfortable-swipe"
local program_exe="/usr/local/bin/$program" local program_exe="/usr/local/bin/$program"
local compile_command="$dir/cpp.compile.sh" 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 conf_path="/usr/local/share/$program/$program.conf"
local dconf_path="$dir/defaults.conf" local dconf_path="$dir/defaults.conf"
local old_conf_path="${XDG_CONFIG_HOME:-$HOME/.config}/$program.conf" local old_conf_path="${XDG_CONFIG_HOME:-$HOME/.config}/$program.conf"

View File

@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=Comfortable Swipe
Comment=Comfortable 3/4-finger swipe gestures
Exec=comfortable-swipe start
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true

View File

@ -1,3 +1,7 @@
/**
* Add all cpp implementation files are registered here.
*/
#ifndef __COMFORTABLE_SWIPE__ #ifndef __COMFORTABLE_SWIPE__
#define __COMFORTABLE_SWIPE__ #define __COMFORTABLE_SWIPE__
@ -19,13 +23,9 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "all_headers.hpp" #include "comfortable_swipe.h"
#include "start.cpp"
/**
* Add all cpp files below to be ready for export.
*/
#include "driver.cpp"
#include "gesture/keyboard_swipe_gesture.cpp" #include "gesture/keyboard_swipe_gesture.cpp"
#include "gesture/mouse_hold_gesture.cpp" #include "gesture/mouse_hold_gesture.cpp"
#include "gesture/swipe_gesture.cpp" #include "gesture/swipe_gesture.cpp"

View File

@ -2,11 +2,11 @@
* Add header files will be imported here. * Add header files will be imported here.
* You can import this as a shorthand: * You can import this as a shorthand:
* *
* #include "../all_headers.hpp" * #include "comfortable_swipe.h"
*/ */
#ifndef __COMFORTABLE_SWIPE__all_headers_hpp__ #ifndef __COMFORTABLE_SWIPE__comfortable_swipe_h__
#define __COMFORTABLE_SWIPE__all_headers_hpp__ #define __COMFORTABLE_SWIPE__comfortable_swipe_h__
/* /*
Comfortable Swipe Comfortable Swipe
@ -27,14 +27,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// global defines // global defines
#ifndef __COMFORTABLE_SWIPE__PROGRAM__ #ifndef COMFORTABLE_SWIPE_PROGRAM
#define __COMFORTABLE_SWIPE__PROGRAM__ "/usr/local/bin/comfortable-swipe" #define COMFORTABLE_SWIPE_PROGRAM "/usr/local/bin/comfortable-swipe"
#endif /* __COMFORTABLE_SWIPE__PROGRAM__ */ #endif /* COMFORTABLE_SWIPE_PROGRAM */
#ifndef __COMFORTABLE_SWIPE__CONFIG__ #ifndef COMFORTABLE_SWIPE_CONFIG
#define __COMFORTABLE_SWIPE__CONFIG__ \ #define COMFORTABLE_SWIPE_CONFIG \
"/usr/local/share/comfortable-swipe/comfortable-swipe.conf" "/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
#endif /* __COMFORTABLE_SWIPE__CONFIG__ */ #endif /* COMFORTABLE_SWIPE_CONFIG */
#ifndef COMFORTABLE_SWIPE_VERSION #ifndef COMFORTABLE_SWIPE_VERSION
#warning COMFORTABLE_SWIPE_VERSION is not defined #warning COMFORTABLE_SWIPE_VERSION is not defined
@ -46,8 +46,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" { extern "C" {
namespace comfortable_swipe { namespace comfortable_swipe {
// driver method
int driver();
// this is found in the util/ folder // this is found in the util/ folder
namespace util { namespace util {
const char *autostart_filename(); const char *autostart_filename();
@ -74,5 +72,6 @@ void stop();
#include "gesture/mouse_hold_gesture.h" #include "gesture/mouse_hold_gesture.h"
#include "gesture/swipe_gesture.h" #include "gesture/swipe_gesture.h"
#include "gesture/xdo_gesture.h" #include "gesture/xdo_gesture.h"
#include "start.h"
#endif /* __COMFORTABLE_SWIPE__all_headers_hpp__ */ #endif /* __COMFORTABLE_SWIPE__comfortable_swipe_h__ */

View File

@ -0,0 +1,79 @@
#ifndef __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__
#define __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "swipe_gesture.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace comfortable_swipe::gesture {
class keyboard_swipe_gesture : public swipe_gesture {
public:
// constructor
keyboard_swipe_gesture(const float threshold, const char *left3 /* 000 */,
const char *left4 /* 001 */,
const char *right3 /* 010 */,
const char *right4 /* 011 */,
const char *up3 /* 100 */, const char *up4 /* 101 */,
const char *down3 /* 110 */,
const char *down4 /* 111 */
);
// destructor
virtual ~keyboard_swipe_gesture();
// hooks that we override
virtual void begin() override;
virtual void update() override;
virtual void end() override;
// override this when keyboard gesture is to be performed
virtual void do_keyboard_gesture(int mask);
protected:
// stores square of threshold so we can compute faster
float threshold_squared;
// stores previous gesture so we don't repeat action
int previous_gesture;
// stores all command strings for xdo to execute
const char **commands;
public:
// static enums we will use for gesture matching
static const int FRESH;
static const int MSK_THREE_FINGERS;
static const int MSK_FOUR_FINGERS;
static const int MSK_NEGATIVE;
static const int MSK_POSITIVE;
static const int MSK_HORIZONTAL;
static const int MSK_VERTICAL;
static const char *const command_map[8];
};
} // namespace comfortable_swipe::gesture
#ifdef __cplusplus
}
#endif
#endif /* __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__ */

View File

@ -0,0 +1,68 @@
#ifndef __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__
#define __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "swipe_gesture.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace comfortable_swipe::gesture {
class mouse_hold_gesture : public swipe_gesture {
public:
// constructor
mouse_hold_gesture(const char *hold3, // 3 finger mouse down
const char *hold4 // 4 finger mouse down
);
// the button being clicked
int button;
virtual ~mouse_hold_gesture();
// override begin and end for mousedown
virtual void begin() override;
virtual void update() override;
virtual void end() override;
// provide our own mouse functions
virtual void do_mousedown(const char *);
virtual void do_mouseup(const char *);
virtual bool is_mousedown() const;
// utility method to parse mouse input given config characters
static int parse_mouse_button(const char *);
protected:
// command holders
const char *hold3;
const char *hold4;
// flag we can use to check if mouse is down
bool flag_mousedown;
};
} // namespace comfortable_swipe::gesture
#ifdef __cplusplus
}
#endif
#endif /* __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__ */

View File

@ -0,0 +1,71 @@
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "xdo_gesture.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace comfortable_swipe::gesture {
class swipe_gesture : public xdo_gesture {
public:
// constructor
swipe_gesture();
// destructor
virtual ~swipe_gesture();
// fields for xdo
int fingers;
// normal values (for touchpad mapping)
float x, y, dx, dy;
// unaccelerated values (for screen mapping)
float ux, uy, udx, udy;
// hooks that we can override (mark as virtual)
virtual void begin();
virtual void update();
virtual void end();
virtual bool parse_line(const char *);
protected:
// location of mouse
int screen_num, ix, iy;
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
bool flag_swiping;
public:
// regex patterns
static const char *GESTURE_BEGIN_REGEX_PATTERN;
static const char *GESTURE_UPDATE_REGEX_PATTERN;
static const char *GESTURE_END_REGEX_PATTERN;
};
} // namespace comfortable_swipe::gesture
#ifdef __cplusplus
}
#endif
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__ */

View File

@ -19,30 +19,26 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
extern "C" extern "C" {
{ #include <xdo.h> // xdo_t
#include <xdo.h> // xdo_t
} }
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
namespace comfortable_swipe namespace comfortable_swipe {
{ namespace gesture {
namespace gesture class xdo_gesture {
{ protected:
class xdo_gesture xdo_t *xdo;
{
protected:
xdo_t * xdo;
public: public:
xdo_gesture(); xdo_gesture();
virtual ~xdo_gesture(); virtual ~xdo_gesture();
}; };
} } // namespace gesture
} } // namespace comfortable_swipe
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../all_headers.hpp" #include "../comfortable_swipe.h"
#include <cstdio> // std::remove #include <cstdio> // std::remove
#include <cstdlib> // std::system #include <cstdlib> // std::system
#include <fstream> // std::ifstream, std::ofstream #include <fstream> // std::ifstream, std::ofstream
@ -51,7 +51,7 @@ void autostart() {
else { else {
fout << "[Desktop Entry]\n" fout << "[Desktop Entry]\n"
"Type=Application\n" "Type=Application\n"
"Exec=bash -c \"" __COMFORTABLE_SWIPE__PROGRAM__ " start\"\n" "Exec=bash -c \"" COMFORTABLE_SWIPE_PROGRAM " start\"\n"
"Hidden=false\n" "Hidden=false\n"
"NoDisplay=false\n" "NoDisplay=false\n"
"X-GNOME-Autostart-enabled=true\n" "X-GNOME-Autostart-enabled=true\n"

View File

@ -19,14 +19,13 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../all_headers.hpp" #include "../start.h"
#include <cstdlib> // std::exit
/** /**
* Starts the comfortable-swipe service by buffering libinput debug-events. * Starts the comfortable-swipe service by buffering libinput debug-events.
*/ */
namespace comfortable_swipe::service { namespace comfortable_swipe::service {
void buffer() { std::exit(comfortable_swipe::driver()); } void buffer() { comfortable_swipe::start(); }
} // namespace comfortable_swipe::service } // namespace comfortable_swipe::service
#endif /* __COMFORTABLE_SWIPE__service_buffer__ */ #endif /* __COMFORTABLE_SWIPE__service_buffer__ */

View File

@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../all_headers.hpp" #include "../comfortable_swipe.h"
#include <cstdio> // std::puts #include <cstdio> // std::puts
namespace comfortable_swipe::service { namespace comfortable_swipe::service {

View File

@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../all_headers.hpp" #include "../comfortable_swipe.h"
#include <cstdio> // std::puts, std::printf #include <cstdio> // std::puts, std::printf
namespace comfortable_swipe::service { namespace comfortable_swipe::service {

View File

@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../all_headers.hpp" #include "../comfortable_swipe.h"
#include <cstdio> // freopen, stdout #include <cstdio> // freopen, stdout
namespace comfortable_swipe::service { namespace comfortable_swipe::service {

View File

@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../all_headers.hpp" #include "../comfortable_swipe.h"
#include <cstdlib> // std::system #include <cstdlib> // std::system
namespace comfortable_swipe::service { namespace comfortable_swipe::service {
@ -29,8 +29,8 @@ namespace comfortable_swipe::service {
* for the technical implementation. * for the technical implementation.
*/ */
void start() { void start() {
(void)std::system(__COMFORTABLE_SWIPE__PROGRAM__ (void)std::system(COMFORTABLE_SWIPE_PROGRAM
" debug | " __COMFORTABLE_SWIPE__PROGRAM__ " buffer"); " debug | " COMFORTABLE_SWIPE_PROGRAM " buffer");
} }
} // namespace comfortable_swipe::service } // namespace comfortable_swipe::service

View File

@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../all_headers.hpp" #include "../comfortable_swipe.h"
#include <array> // std::array #include <array> // std::array
#include <cstdio> // FILE, std::feof, std::fgets, std::printf #include <cstdio> // FILE, std::feof, std::fgets, std::printf
#include <cstdlib> // std::atoi #include <cstdlib> // std::atoi

View File

@ -1,5 +1,5 @@
#ifndef __COMFORTABLE_SWIPE__driver__ #ifndef __COMFORTABLE_SWIPE__start__
#define __COMFORTABLE_SWIPE__driver__ #define __COMFORTABLE_SWIPE__start__
/* /*
Comfortable Swipe 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 <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "all_headers.hpp" #include "comfortable_swipe.h"
#include <cstdio> // fgets_unlocked, stdin #include <cstdio> // fgets_unlocked, stdin
#include <iostream> // std::ios, std::cout, std::cin #include <iostream> // std::ios, std::cout, std::cin
@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* The main driver program. * The main driver program.
*/ */
namespace comfortable_swipe { namespace comfortable_swipe {
int driver() { void start() {
// unsync for faster IO // unsync for faster IO
std::ios::sync_with_stdio(false); std::ios::sync_with_stdio(false);
std::cin.tie(0); std::cin.tie(0);
@ -45,15 +45,23 @@ int driver() {
// hold3=button1 hold button 1 on 3 fingers // hold3=button1 hold button 1 on 3 fingers
// hold4=button3 hold button 3 (right click) on 3 fingers // hold4=button3 hold button 3 (right click) on 3 fingers
// hold3=ignore <do nothing> // hold3=ignore <do nothing>
comfortable_swipe::gesture::mouse_hold_gesture mouse_hold( const char *const hold3 = config["hold3"].c_str();
config["hold3"].c_str(), config["hold4"].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 // 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( comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe(
config.count("threshold") ? std::stof(config["threshold"]) : 0.0, threshold, left3, left4, right3, right4, up3, up4, down3, down4);
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());
// prepare data containers // prepare data containers
std::array<char, 256> line; std::array<char, 256> line;
@ -62,16 +70,13 @@ int driver() {
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL) { while (fgets_unlocked(line.data(), line.size(), stdin) != NULL) {
// prioritize mouse hold gesture first // prioritize mouse hold gesture first
mouse_hold.parse_line(line.data()); mouse_hold.parse_line(line.data());
// if mouse hold fails, try keyboard hold
if (!mouse_hold.is_mousedown()) { 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()); keyboard_swipe.parse_line(line.data());
} }
} }
return 0;
} }
} // namespace comfortable_swipe } // namespace comfortable_swipe
#endif /* __COMFORTABLE_SWIPE__driver__ */ #endif /* __COMFORTABLE_SWIPE__start__ */

8
src/start.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __COMFORTABLE_SWIPE__start_h__
#define __COMFORTABLE_SWIPE__start_h__
namespace comfortable_swipe {
void start();
}
#endif /* __COMFORTABLE_SWIPE__start_h__ */

View File

@ -19,13 +19,13 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../all_headers.hpp" #include "../comfortable_swipe.h"
namespace comfortable_swipe::util { namespace comfortable_swipe::util {
/** /**
* The path where the configuration file is located. * 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 } // namespace comfortable_swipe::util
#endif /* __COMFORTABLE_SWIPE__util_conf_filename__ */ #endif /* __COMFORTABLE_SWIPE__util_conf_filename__ */