Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2c731eb1b | ||
|
|
69c4649f04 | ||
|
|
f2893e4aaa | ||
|
|
7d897ac09e | ||
|
|
fb92169a16 | ||
|
|
2e91ac17fd |
57
.gitignore
vendored
57
.gitignore
vendored
@ -1,6 +1,57 @@
|
||||
# C++ generated headers
|
||||
*.gch
|
||||
|
||||
# IDE-specific
|
||||
.idea
|
||||
.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
|
||||
|
||||
@ -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
|
||||
|
||||
58
CMakeLists.txt
Normal file
58
CMakeLists.txt
Normal 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)
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include "comfortable_swipe/lib"
|
||||
#include <ios> // std::ios
|
||||
#include <iostream> // std::cin, std::cout, std::cerr
|
||||
#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. */
|
||||
|
||||
@ -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__ */
|
||||
@ -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__ */
|
||||
@ -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__ */
|
||||
2
install
2
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"
|
||||
|
||||
8
share/comfortable-swipe.desktop
Normal file
8
share/comfortable-swipe.desktop
Normal 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
|
||||
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Add all cpp implementation files are registered here.
|
||||
*/
|
||||
|
||||
#ifndef __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/>.
|
||||
*/
|
||||
|
||||
#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/mouse_hold_gesture.cpp"
|
||||
#include "gesture/swipe_gesture.cpp"
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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__ */
|
||||
79
src/gesture/keyboard_swipe_gesture.h
Normal file
79
src/gesture/keyboard_swipe_gesture.h
Normal 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__ */
|
||||
68
src/gesture/mouse_hold_gesture.h
Normal file
68
src/gesture/mouse_hold_gesture.h
Normal 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__ */
|
||||
71
src/gesture/swipe_gesture.h
Normal file
71
src/gesture/swipe_gesture.h
Normal 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__ */
|
||||
@ -19,8 +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/>.
|
||||
*/
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#include <xdo.h> // xdo_t
|
||||
}
|
||||
|
||||
@ -28,12 +27,9 @@ extern "C"
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
namespace comfortable_swipe
|
||||
{
|
||||
namespace gesture
|
||||
{
|
||||
class xdo_gesture
|
||||
{
|
||||
namespace comfortable_swipe {
|
||||
namespace gesture {
|
||||
class xdo_gesture {
|
||||
protected:
|
||||
xdo_t *xdo;
|
||||
|
||||
@ -41,8 +37,8 @@ namespace comfortable_swipe
|
||||
xdo_gesture();
|
||||
virtual ~xdo_gesture();
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace gesture
|
||||
} // namespace comfortable_swipe
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include "../all_headers.hpp"
|
||||
#include "../comfortable_swipe.h"
|
||||
#include <cstdio> // std::remove
|
||||
#include <cstdlib> // std::system
|
||||
#include <fstream> // 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"
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include "../all_headers.hpp"
|
||||
#include <cstdlib> // 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__ */
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include "../all_headers.hpp"
|
||||
#include "../comfortable_swipe.h"
|
||||
#include <cstdio> // std::puts
|
||||
|
||||
namespace comfortable_swipe::service {
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include "../all_headers.hpp"
|
||||
#include "../comfortable_swipe.h"
|
||||
#include <cstdio> // std::puts, std::printf
|
||||
|
||||
namespace comfortable_swipe::service {
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include "../all_headers.hpp"
|
||||
#include "../comfortable_swipe.h"
|
||||
#include <cstdio> // freopen, stdout
|
||||
|
||||
namespace comfortable_swipe::service {
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include "../all_headers.hpp"
|
||||
#include "../comfortable_swipe.h"
|
||||
#include <cstdlib> // 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
|
||||
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include "../all_headers.hpp"
|
||||
#include "../comfortable_swipe.h"
|
||||
#include <array> // std::array
|
||||
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
||||
#include <cstdlib> // std::atoi
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "all_headers.hpp"
|
||||
#include "comfortable_swipe.h"
|
||||
#include <cstdio> // fgets_unlocked, stdin
|
||||
#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.
|
||||
*/
|
||||
namespace comfortable_swipe {
|
||||
int driver() {
|
||||
void start() {
|
||||
// unsync for faster IO
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(0);
|
||||
@ -45,15 +45,23 @@ int driver() {
|
||||
// hold3=button1 hold button 1 on 3 fingers
|
||||
// hold4=button3 hold button 3 (right click) on 3 fingers
|
||||
// hold3=ignore <do nothing>
|
||||
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<char, 256> line;
|
||||
@ -62,16 +70,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__ */
|
||||
8
src/start.h
Normal file
8
src/start.h
Normal 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__ */
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#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__ */
|
||||
Loading…
Reference in New Issue
Block a user