Skip to content

Commit ab30e72

Browse files
Release v0.0.3 (#5)
* 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
1 parent ce8ca61 commit ab30e72

File tree

8 files changed

+121
-60
lines changed

8 files changed

+121
-60
lines changed

.idea/misc.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.12.1)
22
project(gebaar)
33
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
44
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors")
56
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
67

78
add_executable(gebaard

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gebaar
22
=========
3-
[![Gitter chat](https://badges.gitter.im/gebaar-libinput/community.png)](https://gitter.im/gebaar-libinput/community)
3+
[![](https://img.shields.io/gitter/room/gebaar-libinput/community.svg?style=flat)](https://gitter.im/gebaar-libinput/community)
44

55
WM Independent Touchpad Gesture Daemon for libinput
66

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

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

50+
### Repository versions
5051

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

5254
### Examples
5355

src/config/config.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,53 @@
2020
#include <zconf.h>
2121
#include "config.h"
2222

23-
bool gebaar::config::Config::find_config_file()
23+
/**
24+
* Check if config file exists at current path
25+
*/
26+
bool gebaar::config::Config::config_file_exists()
2427
{
2528
auto true_path = std::filesystem::path(config_file_path);
2629
return std::filesystem::exists(true_path);
2730
}
2831

32+
/**
33+
* Load Configuration from TOML file
34+
*/
2935
void gebaar::config::Config::load_config()
3036
{
31-
if (find_home_folder()) {
32-
if (find_config_file()) {
37+
if (find_config_file()) {
38+
if (config_file_exists()) {
3339
config = cpptoml::parse_file(std::filesystem::path(config_file_path));
34-
swipe_three_up_command = *config->get_qualified_as<std::string>("commands.swipe.three.up");
35-
swipe_three_down_command = *config->get_qualified_as<std::string>("commands.swipe.three.down");
36-
swipe_three_left_command = *config->get_qualified_as<std::string>("commands.swipe.three.left");
37-
swipe_three_right_command = *config->get_qualified_as<std::string>("commands.swipe.three.right");
38-
swipe_four_up_command = *config->get_qualified_as<std::string>("commands.swipe.four.up");
39-
swipe_four_down_command = *config->get_qualified_as<std::string>("commands.swipe.four.down");
40-
swipe_four_left_command = *config->get_qualified_as<std::string>("commands.swipe.four.left");
41-
swipe_four_right_command = *config->get_qualified_as<std::string>("commands.swipe.four.right");
40+
41+
swipe_three_commands[1] = *config->get_qualified_as<std::string>("commands.swipe.three.left_up");
42+
swipe_three_commands[2] = *config->get_qualified_as<std::string>("commands.swipe.three.up");
43+
swipe_three_commands[3] = *config->get_qualified_as<std::string>("commands.swipe.three.right_up");
44+
swipe_three_commands[4] = *config->get_qualified_as<std::string>("commands.swipe.three.left");
45+
swipe_three_commands[6] = *config->get_qualified_as<std::string>("commands.swipe.three.right");
46+
swipe_three_commands[7] = *config->get_qualified_as<std::string>("commands.swipe.three.left_down");
47+
swipe_three_commands[8] = *config->get_qualified_as<std::string>("commands.swipe.three.down");
48+
swipe_three_commands[9] = *config->get_qualified_as<std::string>("commands.swipe.three.right_down");
49+
50+
swipe_four_commands[1] = *config->get_qualified_as<std::string>("commands.swipe.four.left_up");
51+
swipe_four_commands[2] = *config->get_qualified_as<std::string>("commands.swipe.four.up");
52+
swipe_four_commands[3] = *config->get_qualified_as<std::string>("commands.swipe.four.right_up");
53+
swipe_four_commands[4] = *config->get_qualified_as<std::string>("commands.swipe.four.left");
54+
swipe_four_commands[6] = *config->get_qualified_as<std::string>("commands.swipe.four.right");
55+
swipe_four_commands[7] = *config->get_qualified_as<std::string>("commands.swipe.four.left_down");
56+
swipe_four_commands[8] = *config->get_qualified_as<std::string>("commands.swipe.four.down");
57+
swipe_four_commands[9] = *config->get_qualified_as<std::string>("commands.swipe.four.right_down");
58+
4259
loaded = true;
4360
}
4461
}
4562

4663
}
4764

48-
bool gebaar::config::Config::find_home_folder()
65+
/**
66+
* Find the configuration file according to XDG spec
67+
* @return bool
68+
*/
69+
bool gebaar::config::Config::find_config_file()
4970
{
5071
const char* temp_path;
5172
temp_path = getenv("XDG_CONFIG_HOME");

src/config/config.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,13 @@ namespace gebaar::config {
3333

3434
void load_config();
3535

36-
std::string swipe_four_up_command;
37-
std::string swipe_four_down_command;
38-
std::string swipe_four_left_command;
39-
std::string swipe_four_right_command;
40-
std::string swipe_three_up_command;
41-
std::string swipe_three_down_command;
42-
std::string swipe_three_left_command;
43-
std::string swipe_three_right_command;
36+
std::string swipe_three_commands[10];
37+
std::string swipe_four_commands[10];
38+
4439
private:
45-
bool find_config_file();
40+
bool config_file_exists();
4641

47-
bool find_home_folder();
42+
bool find_config_file();
4843

4944
std::string config_file_path;
5045
std::shared_ptr<cpptoml::table> config;

src/daemonizer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
#include "daemonizer.h"
2121

22-
22+
/**
23+
* Forking logic for classic style daemon functionality
24+
*
25+
* @return bool that denotes fork success
26+
*/
2327
bool gebaar::daemonizer::Daemonizer::daemonize()
2428
{
2529
pid_t pid = 0;

src/io/input.cpp

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,77 +19,103 @@
1919
#include <poll.h>
2020
#include "input.h"
2121

22+
/**
23+
* Input system constructor, we pass our Configuration object via a shared pointer
24+
*
25+
* @param config_ptr shared pointer to configuration object
26+
*/
2227
gebaar::io::Input::Input(std::shared_ptr<gebaar::config::Config> const& config_ptr)
2328
{
2429
config = config_ptr;
2530
gesture_swipe_event = {};
2631
}
2732

33+
/**
34+
* Initialize the libinput context
35+
*
36+
* @return bool
37+
*/
2838
bool gebaar::io::Input::initialize_context()
2939
{
3040
udev = udev_new();
3141
libinput = libinput_udev_create_context(&libinput_interface, nullptr, udev);
3242
return libinput_udev_assign_seat(libinput, "seat0")==0;
3343
}
3444

45+
/**
46+
* This event has no coordinates, so it's an event that gives us a begin or end signal.
47+
* If it begins, we get the amount of fingers used.
48+
* If it ends, we check what kind of gesture we received.
49+
*
50+
* @param gev Gesture Event
51+
* @param begin Boolean to denote begin or end of gesture
52+
*/
3553
void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture* gev, bool begin)
3654
{
3755
if (begin) {
3856
gesture_swipe_event.fingers = libinput_event_gesture_get_finger_count(gev);
3957
}
4058
else {
41-
if (abs(gesture_swipe_event.x)>abs(gesture_swipe_event.y)) {
42-
if (gesture_swipe_event.x<0) {
43-
if (gesture_swipe_event.fingers==3) {
44-
std::system(config->swipe_three_left_command.c_str());
45-
}
46-
else if (gesture_swipe_event.fingers==4) {
47-
std::system(config->swipe_four_left_command.c_str());
48-
}
59+
double x = gesture_swipe_event.x;
60+
double y = gesture_swipe_event.y;
61+
int swipe_type = 5; // middle = no swipe
62+
// 1 = left_up, 2 = up, 3 = right_up...
63+
// 1 2 3
64+
// 4 5 6
65+
// 7 8 9
66+
const double OBLIQUE_RATIO = 0.414; // =~ tan(22.5);
67+
68+
if (abs(x) > abs(y)) {
69+
// left or right swipe
70+
swipe_type += x < 0 ? -1 : 1;
71+
72+
// check for oblique swipe
73+
if (abs(y) / abs(x) > OBLIQUE_RATIO) {
74+
swipe_type += y < 0 ? -3 : 3;
4975
}
50-
else {
51-
if (gesture_swipe_event.fingers==3) {
52-
std::system(config->swipe_three_right_command.c_str());
53-
}
54-
else if (gesture_swipe_event.fingers==4) {
55-
std::system(config->swipe_four_right_command.c_str());
56-
}
76+
} else {
77+
// up of down swipe
78+
swipe_type += y < 0 ? -3 : 3;
79+
80+
// check for oblique swipe
81+
if (abs(x) / abs(y) > OBLIQUE_RATIO) {
82+
swipe_type += x < 0 ? -1 : 1;
5783
}
5884
}
59-
else {
60-
if (gesture_swipe_event.y<0) {
61-
if (gesture_swipe_event.fingers==3) {
62-
std::system(config->swipe_three_up_command.c_str());
63-
}
64-
else if (gesture_swipe_event.fingers==4) {
65-
std::system(config->swipe_four_up_command.c_str());
66-
}
67-
}
68-
else {
69-
if (gesture_swipe_event.fingers==3) {
70-
std::system(config->swipe_three_down_command.c_str());
71-
}
72-
else if (gesture_swipe_event.fingers==4) {
73-
std::system(config->swipe_four_down_command.c_str());
74-
}
75-
}
85+
86+
if (gesture_swipe_event.fingers == 3) {
87+
std::system(config->swipe_three_commands[swipe_type].c_str());
88+
} else if (gesture_swipe_event.fingers == 4) {
89+
std::system(config->swipe_four_commands[swipe_type].c_str());
7690
}
91+
7792
gesture_swipe_event = {};
7893
}
7994
}
8095

96+
/**
97+
* Swipe events with coordinates, add it to the current tally
98+
* @param gev Gesture Event
99+
*/
81100
void gebaar::io::Input::handle_swipe_event_with_coords(libinput_event_gesture* gev)
82101
{
83102
gesture_swipe_event.x += libinput_event_gesture_get_dx(gev);
84103
gesture_swipe_event.y += libinput_event_gesture_get_dy(gev);
85104
}
86105

106+
/**
107+
* Initialize the input system
108+
* @return bool
109+
*/
87110
bool gebaar::io::Input::initialize()
88111
{
89112
initialize_context();
90-
return find_gesture_device();
113+
return gesture_device_exists();
91114
}
92115

116+
/**
117+
* Run a poll loop on the file descriptor that libinput gives us
118+
*/
93119
void gebaar::io::Input::start_loop()
94120
{
95121
struct pollfd fds{};
@@ -107,7 +133,11 @@ gebaar::io::Input::~Input()
107133
libinput_unref(libinput);
108134
}
109135

110-
bool gebaar::io::Input::find_gesture_device()
136+
/**
137+
* Check if there's a device that supports gestures on this system
138+
* @return
139+
*/
140+
bool gebaar::io::Input::gesture_device_exists()
111141
{
112142
bool device_found = false;
113143
while ((libinput_event = libinput_get_event(libinput))!=nullptr) {
@@ -122,6 +152,9 @@ bool gebaar::io::Input::find_gesture_device()
122152
return device_found;
123153
}
124154

155+
/**
156+
* Handle an event from libinput and run the appropriate action per event type
157+
*/
125158
void gebaar::io::Input::handle_event()
126159
{
127160
libinput_dispatch(libinput);

src/io/input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace gebaar::io {
5151

5252
bool initialize_context();
5353

54-
bool find_gesture_device();
54+
bool gesture_device_exists();
5555

5656
static int open_restricted(const char* path, int flags, void* user_data)
5757
{

0 commit comments

Comments
 (0)