Skip to content

Commit

Permalink
Release v0.0.3 (#5)
Browse files Browse the repository at this point in the history
* Update README.md to reflect version bump

* Update to README.md, new shields

Added AUR Package shield
Changed gitter.im shield

* Added support for oblique gesture swipes.

To add the support the config class was modified to include the new
gestures types: left_up, right_up, left_down, right_down.
Also changed the way the commands are saved in the config class, so
there won't be a need for a lot of if statements to handle 4 finger
swipes and 3 finger swipes.
Finally, the handle_swipe_event_without_coords was modified to detect
the oblique swipes.

* Commenting the code a bit and some minor cosmetic and semantic changes

- Added comments to each function
- Increased string array size to 10 in config.h even though we only need 9 slots, I'm being a bit pedantic about this
- Adding some build flags to CMakeLists.txt to show every error, preferably we'd get clean output eventually
- Renamed find_gesture_device to gesture_device_exists in Input class
- Renamed find_config_file to config_file_exists as this actually describes the logic of this function in Config class
- Renamed find_home_folder to find_config_file in Config class in preparation to adding /etc/gebaar/gebaard.toml to list of possible config file locations

* Prepare for release by bumping up version in README.md
  • Loading branch information
Coffee2CodeNL authored Feb 23, 2019
1 parent ce8ca61 commit ab30e72
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.12.1)
project(gebaar)
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

add_executable(gebaard
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gebaar
=========
[![Gitter chat](https://badges.gitter.im/gebaar-libinput/community.png)](https://gitter.im/gebaar-libinput/community)
[![](https://img.shields.io/gitter/room/gebaar-libinput/community.svg?style=flat)](https://gitter.im/gebaar-libinput/community)

WM Independent Touchpad Gesture Daemon for libinput

Expand All @@ -19,7 +19,7 @@ This is more stable, faster, and more efficient as it **does not parse the outpu
### How to build and install

1. Clone the repository via `git clone https://github.com/Coffee2CodeNL/gebaar-libinput`
2. Check out the latest version (`git checkout v0.0.1`)
2. Check out the latest version (`git checkout v0.0.3`)
3. Run `git submodule update --init` in the root folder
4. Run `mkdir build && cd build`
5. Run `cmake ..`
Expand Down Expand Up @@ -47,7 +47,9 @@ left = ""
right = ""
```

### Repository versions

![](https://img.shields.io/aur/version/gebaar.svg?style=flat)

### Examples

Expand Down
45 changes: 33 additions & 12 deletions src/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,53 @@
#include <zconf.h>
#include "config.h"

bool gebaar::config::Config::find_config_file()
/**
* Check if config file exists at current path
*/
bool gebaar::config::Config::config_file_exists()
{
auto true_path = std::filesystem::path(config_file_path);
return std::filesystem::exists(true_path);
}

/**
* Load Configuration from TOML file
*/
void gebaar::config::Config::load_config()
{
if (find_home_folder()) {
if (find_config_file()) {
if (find_config_file()) {
if (config_file_exists()) {
config = cpptoml::parse_file(std::filesystem::path(config_file_path));
swipe_three_up_command = *config->get_qualified_as<std::string>("commands.swipe.three.up");
swipe_three_down_command = *config->get_qualified_as<std::string>("commands.swipe.three.down");
swipe_three_left_command = *config->get_qualified_as<std::string>("commands.swipe.three.left");
swipe_three_right_command = *config->get_qualified_as<std::string>("commands.swipe.three.right");
swipe_four_up_command = *config->get_qualified_as<std::string>("commands.swipe.four.up");
swipe_four_down_command = *config->get_qualified_as<std::string>("commands.swipe.four.down");
swipe_four_left_command = *config->get_qualified_as<std::string>("commands.swipe.four.left");
swipe_four_right_command = *config->get_qualified_as<std::string>("commands.swipe.four.right");

swipe_three_commands[1] = *config->get_qualified_as<std::string>("commands.swipe.three.left_up");
swipe_three_commands[2] = *config->get_qualified_as<std::string>("commands.swipe.three.up");
swipe_three_commands[3] = *config->get_qualified_as<std::string>("commands.swipe.three.right_up");
swipe_three_commands[4] = *config->get_qualified_as<std::string>("commands.swipe.three.left");
swipe_three_commands[6] = *config->get_qualified_as<std::string>("commands.swipe.three.right");
swipe_three_commands[7] = *config->get_qualified_as<std::string>("commands.swipe.three.left_down");
swipe_three_commands[8] = *config->get_qualified_as<std::string>("commands.swipe.three.down");
swipe_three_commands[9] = *config->get_qualified_as<std::string>("commands.swipe.three.right_down");

swipe_four_commands[1] = *config->get_qualified_as<std::string>("commands.swipe.four.left_up");
swipe_four_commands[2] = *config->get_qualified_as<std::string>("commands.swipe.four.up");
swipe_four_commands[3] = *config->get_qualified_as<std::string>("commands.swipe.four.right_up");
swipe_four_commands[4] = *config->get_qualified_as<std::string>("commands.swipe.four.left");
swipe_four_commands[6] = *config->get_qualified_as<std::string>("commands.swipe.four.right");
swipe_four_commands[7] = *config->get_qualified_as<std::string>("commands.swipe.four.left_down");
swipe_four_commands[8] = *config->get_qualified_as<std::string>("commands.swipe.four.down");
swipe_four_commands[9] = *config->get_qualified_as<std::string>("commands.swipe.four.right_down");

loaded = true;
}
}

}

bool gebaar::config::Config::find_home_folder()
/**
* Find the configuration file according to XDG spec
* @return bool
*/
bool gebaar::config::Config::find_config_file()
{
const char* temp_path;
temp_path = getenv("XDG_CONFIG_HOME");
Expand Down
15 changes: 5 additions & 10 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,13 @@ namespace gebaar::config {

void load_config();

std::string swipe_four_up_command;
std::string swipe_four_down_command;
std::string swipe_four_left_command;
std::string swipe_four_right_command;
std::string swipe_three_up_command;
std::string swipe_three_down_command;
std::string swipe_three_left_command;
std::string swipe_three_right_command;
std::string swipe_three_commands[10];
std::string swipe_four_commands[10];

private:
bool find_config_file();
bool config_file_exists();

bool find_home_folder();
bool find_config_file();

std::string config_file_path;
std::shared_ptr<cpptoml::table> config;
Expand Down
6 changes: 5 additions & 1 deletion src/daemonizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

#include "daemonizer.h"


/**
* Forking logic for classic style daemon functionality
*
* @return bool that denotes fork success
*/
bool gebaar::daemonizer::Daemonizer::daemonize()
{
pid_t pid = 0;
Expand Down
101 changes: 67 additions & 34 deletions src/io/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,103 @@
#include <poll.h>
#include "input.h"

/**
* Input system constructor, we pass our Configuration object via a shared pointer
*
* @param config_ptr shared pointer to configuration object
*/
gebaar::io::Input::Input(std::shared_ptr<gebaar::config::Config> const& config_ptr)
{
config = config_ptr;
gesture_swipe_event = {};
}

/**
* Initialize the libinput context
*
* @return bool
*/
bool gebaar::io::Input::initialize_context()
{
udev = udev_new();
libinput = libinput_udev_create_context(&libinput_interface, nullptr, udev);
return libinput_udev_assign_seat(libinput, "seat0")==0;
}

/**
* This event has no coordinates, so it's an event that gives us a begin or end signal.
* If it begins, we get the amount of fingers used.
* If it ends, we check what kind of gesture we received.
*
* @param gev Gesture Event
* @param begin Boolean to denote begin or end of gesture
*/
void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture* gev, bool begin)
{
if (begin) {
gesture_swipe_event.fingers = libinput_event_gesture_get_finger_count(gev);
}
else {
if (abs(gesture_swipe_event.x)>abs(gesture_swipe_event.y)) {
if (gesture_swipe_event.x<0) {
if (gesture_swipe_event.fingers==3) {
std::system(config->swipe_three_left_command.c_str());
}
else if (gesture_swipe_event.fingers==4) {
std::system(config->swipe_four_left_command.c_str());
}
double x = gesture_swipe_event.x;
double y = gesture_swipe_event.y;
int swipe_type = 5; // middle = no swipe
// 1 = left_up, 2 = up, 3 = right_up...
// 1 2 3
// 4 5 6
// 7 8 9
const double OBLIQUE_RATIO = 0.414; // =~ tan(22.5);

if (abs(x) > abs(y)) {
// left or right swipe
swipe_type += x < 0 ? -1 : 1;

// check for oblique swipe
if (abs(y) / abs(x) > OBLIQUE_RATIO) {
swipe_type += y < 0 ? -3 : 3;
}
else {
if (gesture_swipe_event.fingers==3) {
std::system(config->swipe_three_right_command.c_str());
}
else if (gesture_swipe_event.fingers==4) {
std::system(config->swipe_four_right_command.c_str());
}
} else {
// up of down swipe
swipe_type += y < 0 ? -3 : 3;

// check for oblique swipe
if (abs(x) / abs(y) > OBLIQUE_RATIO) {
swipe_type += x < 0 ? -1 : 1;
}
}
else {
if (gesture_swipe_event.y<0) {
if (gesture_swipe_event.fingers==3) {
std::system(config->swipe_three_up_command.c_str());
}
else if (gesture_swipe_event.fingers==4) {
std::system(config->swipe_four_up_command.c_str());
}
}
else {
if (gesture_swipe_event.fingers==3) {
std::system(config->swipe_three_down_command.c_str());
}
else if (gesture_swipe_event.fingers==4) {
std::system(config->swipe_four_down_command.c_str());
}
}

if (gesture_swipe_event.fingers == 3) {
std::system(config->swipe_three_commands[swipe_type].c_str());
} else if (gesture_swipe_event.fingers == 4) {
std::system(config->swipe_four_commands[swipe_type].c_str());
}

gesture_swipe_event = {};
}
}

/**
* Swipe events with coordinates, add it to the current tally
* @param gev Gesture Event
*/
void gebaar::io::Input::handle_swipe_event_with_coords(libinput_event_gesture* gev)
{
gesture_swipe_event.x += libinput_event_gesture_get_dx(gev);
gesture_swipe_event.y += libinput_event_gesture_get_dy(gev);
}

/**
* Initialize the input system
* @return bool
*/
bool gebaar::io::Input::initialize()
{
initialize_context();
return find_gesture_device();
return gesture_device_exists();
}

/**
* Run a poll loop on the file descriptor that libinput gives us
*/
void gebaar::io::Input::start_loop()
{
struct pollfd fds{};
Expand All @@ -107,7 +133,11 @@ gebaar::io::Input::~Input()
libinput_unref(libinput);
}

bool gebaar::io::Input::find_gesture_device()
/**
* Check if there's a device that supports gestures on this system
* @return
*/
bool gebaar::io::Input::gesture_device_exists()
{
bool device_found = false;
while ((libinput_event = libinput_get_event(libinput))!=nullptr) {
Expand All @@ -122,6 +152,9 @@ bool gebaar::io::Input::find_gesture_device()
return device_found;
}

/**
* Handle an event from libinput and run the appropriate action per event type
*/
void gebaar::io::Input::handle_event()
{
libinput_dispatch(libinput);
Expand Down
2 changes: 1 addition & 1 deletion src/io/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace gebaar::io {

bool initialize_context();

bool find_gesture_device();
bool gesture_device_exists();

static int open_restricted(const char* path, int flags, void* user_data)
{
Expand Down

0 comments on commit ab30e72

Please sign in to comment.