Update status command and add config command (#55)
* Add configurations to status * Update comment of status * Add config command * Modify README
This commit is contained in:
parent
204a422f2d
commit
7d76db6693
22
README.md
22
README.md
@ -41,13 +41,21 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
```
|
```
|
||||||
comfortable-swipe autostart
|
comfortable-swipe autostart
|
||||||
```
|
```
|
||||||
5. _Optional_: Change [configurations](#configurations) (see below). After making changes, run
|
5. Check the status of your application by running
|
||||||
```
|
```
|
||||||
comfortable-swipe restart
|
comfortable-swipe status
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configurations
|
## Configurations
|
||||||
Comfortable swipe makes use of keyboard shortcuts for configurations. The configuration file is located at `/usr/local/share/comfortable-swipe/comfortable-swipe.conf`. Make sure to run `comfortable-swipe restart` after making changes.
|
Comfortable swipe makes use of keyboard shortcuts for configurations. Edit by running
|
||||||
|
```
|
||||||
|
nano $(comfortable-swipe config)
|
||||||
|
```
|
||||||
|
|
||||||
|
Make sure to run after making changes:
|
||||||
|
```
|
||||||
|
comfortable-swipe restart
|
||||||
|
```
|
||||||
|
|
||||||
Property | Description | Default Value | Default Behavior
|
Property | Description | Default Value | Default Behavior
|
||||||
--------- | ----------- | -------------- | -----
|
--------- | ----------- | -------------- | -----
|
||||||
@ -80,7 +88,13 @@ Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete li
|
|||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
You can check your touchpad driver by running `comfortable-swipe debug`. This is an alias of `libinput debug-events`. This logs all gestures you make on your touchpad, along with other input-based events that can be captured by libinput.
|
You can check your touchpad driver by running
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe debug
|
||||||
|
```
|
||||||
|
|
||||||
|
This is an alias of `libinput debug-events`. This logs all gestures you make on your touchpad, along with other input-based events that can be captured by libinput.
|
||||||
|
|
||||||
A working swipe gesture will show the following:
|
A working swipe gesture will show the following:
|
||||||
|
|
||||||
|
|||||||
@ -51,6 +51,9 @@ int main(int argc, char** args)
|
|||||||
else if (arg == "autostart")
|
else if (arg == "autostart")
|
||||||
comfortable_swipe::service::autostart();
|
comfortable_swipe::service::autostart();
|
||||||
|
|
||||||
|
else if (arg == "config")
|
||||||
|
comfortable_swipe::service::config();
|
||||||
|
|
||||||
else if (arg == "debug")
|
else if (arg == "debug")
|
||||||
comfortable_swipe::service::debug();
|
comfortable_swipe::service::debug();
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "gesture/swipe_gesture.regex.cpp"
|
#include "gesture/swipe_gesture.regex.cpp"
|
||||||
#include "service/autostart.cpp"
|
#include "service/autostart.cpp"
|
||||||
#include "service/buffer.cpp"
|
#include "service/buffer.cpp"
|
||||||
|
#include "service/config.cpp"
|
||||||
#include "service/debug.cpp"
|
#include "service/debug.cpp"
|
||||||
#include "service/help.cpp"
|
#include "service/help.cpp"
|
||||||
#include "service/restart.cpp"
|
#include "service/restart.cpp"
|
||||||
|
|||||||
@ -198,14 +198,14 @@ namespace comfortable_swipe::gesture
|
|||||||
const int swipe_gesture::MSK_VERTICAL = 4;
|
const int swipe_gesture::MSK_VERTICAL = 4;
|
||||||
const int swipe_gesture::FRESH = -1;
|
const int swipe_gesture::FRESH = -1;
|
||||||
const char * const swipe_gesture::command_map[8] = {
|
const char * const swipe_gesture::command_map[8] = {
|
||||||
"left 3",
|
"left3",
|
||||||
"left 4",
|
"left4",
|
||||||
"right 3",
|
"right3",
|
||||||
"right 4",
|
"right4",
|
||||||
"up 3",
|
"up3",
|
||||||
"up 4",
|
"up4",
|
||||||
"down 3",
|
"down3",
|
||||||
"down 4"
|
"down4"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,6 +50,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
void autostart();
|
void autostart();
|
||||||
void buffer();
|
void buffer();
|
||||||
|
void config();
|
||||||
void debug();
|
void debug();
|
||||||
void help();
|
void help();
|
||||||
void restart();
|
void restart();
|
||||||
|
|||||||
38
lib/service/config.cpp
Normal file
38
lib/service/config.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_config__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_config__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../index.hpp"
|
||||||
|
#include <cstdio> // std::puts
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Prints where the config file of comfortable swipe is located.
|
||||||
|
*
|
||||||
|
* Usage: nano $(comfortable-swipe config)
|
||||||
|
*/
|
||||||
|
void config()
|
||||||
|
{
|
||||||
|
std::puts(comfortable_swipe::util::conf_filename());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_config__ */
|
||||||
@ -30,7 +30,7 @@ namespace comfortable_swipe::service
|
|||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
using comfortable_swipe::util::conf_filename;
|
using comfortable_swipe::util::conf_filename;
|
||||||
std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|debug]");
|
std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|config|debug|status]");
|
||||||
std::puts("");
|
std::puts("");
|
||||||
std::puts("start - starts 3/4-finger gesture service");
|
std::puts("start - starts 3/4-finger gesture service");
|
||||||
std::puts("stop - stops 3/4-finger gesture service");
|
std::puts("stop - stops 3/4-finger gesture service");
|
||||||
@ -38,6 +38,7 @@ namespace comfortable_swipe::service
|
|||||||
std::puts("autostart - automatically run on startup (toggleable)");
|
std::puts("autostart - automatically run on startup (toggleable)");
|
||||||
std::puts("buffer - parses output of libinput debug-events");
|
std::puts("buffer - parses output of libinput debug-events");
|
||||||
std::puts("help - shows the help dialog");
|
std::puts("help - shows the help dialog");
|
||||||
|
std::puts("config - locates the config file [/usr/share/comfortable-swipe/comfortable-swipe.conf]");
|
||||||
std::puts("debug - logs raw output from input events taken from libinput");
|
std::puts("debug - logs raw output from input events taken from libinput");
|
||||||
std::puts("status - checks status of program and autostart");
|
std::puts("status - checks status of program and autostart");
|
||||||
std::puts("");
|
std::puts("");
|
||||||
|
|||||||
@ -26,11 +26,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <array> // std::array
|
#include <array> // std::array
|
||||||
#include <cstdlib> // std::atoi
|
#include <cstdlib> // std::atoi
|
||||||
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
||||||
|
#include <regex> // std::cmatch, std::regex, std::regex_match
|
||||||
|
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Restarts the comfortable-swipe service.
|
* Prints the status of comfortable-swipe.
|
||||||
*/
|
*/
|
||||||
void status()
|
void status()
|
||||||
{
|
{
|
||||||
@ -52,6 +53,44 @@ namespace comfortable_swipe::service
|
|||||||
// print status
|
// print status
|
||||||
std::printf("program is %s\n", running ? "ON" : "OFF");
|
std::printf("program is %s\n", running ? "ON" : "OFF");
|
||||||
std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
|
std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
|
||||||
|
std::printf("config file at %s\n", comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// check status of configuration file
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// print keys and values of config file
|
||||||
|
std::printf("\nConfigurations:\n");
|
||||||
|
|
||||||
|
// print threshold
|
||||||
|
if (config.count("threshold") > 0)
|
||||||
|
{
|
||||||
|
auto & threshold = config["threshold"];
|
||||||
|
|
||||||
|
// check if regex pattern matches threshold
|
||||||
|
std::cmatch matches;
|
||||||
|
bool ok = (std::regex_match(threshold.data(), matches, std::regex("^\\d+(?:\\.\\d+)??$")) != 0);
|
||||||
|
|
||||||
|
// print status of threshold
|
||||||
|
std::printf(" %9s is %s (%s)\n", "threshold", ok ? "OK" : "INVALID", threshold.data());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::printf(" %9s is OFF\n", "threshold");
|
||||||
|
|
||||||
|
// print swipe commands
|
||||||
|
for (auto &command : comfortable_swipe::gesture::swipe_gesture::command_map)
|
||||||
|
{
|
||||||
|
if (config.count(command) > 0)
|
||||||
|
std::printf(" %9s is OK (%s)\n", command, config[command].data());
|
||||||
|
else
|
||||||
|
std::printf(" %9s is OFF\n", command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error& e)
|
||||||
|
{
|
||||||
|
std::printf("config error: %s\n", e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,9 +22,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <map> // std::map
|
#include <map> // std::map
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include <fstream> // std::ifstream
|
#include <fstream> // std::ifstream
|
||||||
#include <iostream> // std::cerr, std::endl, std::getline
|
#include <sstream> // std::ostringstream
|
||||||
|
#include <iostream> // std::endl, std::getline
|
||||||
#include <cstdlib> // exit
|
#include <cstdlib> // exit
|
||||||
#include <cctype> // std::isspace
|
#include <cctype> // std::isspace
|
||||||
|
#include <stdexcept> // std::runtime_error
|
||||||
|
|
||||||
namespace comfortable_swipe::util
|
namespace comfortable_swipe::util
|
||||||
{
|
{
|
||||||
@ -41,8 +43,7 @@ namespace comfortable_swipe::util
|
|||||||
|
|
||||||
if (!fin.is_open())
|
if (!fin.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "file \"" << filename << "\" does not exist!" << std::endl;
|
throw std::runtime_error("config file does not exist");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string line, token[2];
|
static std::string line, token[2];
|
||||||
@ -65,9 +66,10 @@ namespace comfortable_swipe::util
|
|||||||
{
|
{
|
||||||
if (++equal_flag > 1)
|
if (++equal_flag > 1)
|
||||||
{
|
{
|
||||||
std::cerr << "error in conf file " << filename << std::endl;
|
std::ostringstream stream;
|
||||||
std::cerr << "multiple equal signs in line " << line_number << std::endl;
|
stream << "error in conf file " << filename << std::endl;
|
||||||
exit(1);
|
stream << "multiple equal signs in line " << line_number << std::endl;
|
||||||
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!std::isspace(line[i]))
|
else if (!std::isspace(line[i]))
|
||||||
@ -84,9 +86,10 @@ namespace comfortable_swipe::util
|
|||||||
// no equal sign found in non-empty line
|
// no equal sign found in non-empty line
|
||||||
if (equal_flag == 0)
|
if (equal_flag == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "error in conf file: " << filename << std::endl;
|
std::ostringstream stream;
|
||||||
std::cerr << "equal sign expected in line " << line_number << std::endl;
|
stream << "error in conf file: " << filename << std::endl;
|
||||||
exit(1);
|
stream << "equal sign expected in line " << line_number << std::endl;
|
||||||
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// equal sign found, add to tokens
|
// equal sign found, add to tokens
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user