diff --git a/.gitignore b/.gitignore
index 4753a05..2fca53d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,6 @@
# C++ generated headers
*.gch
+
+# IDE-specific
+.idea
+.vscode
diff --git a/comfortable-swipe.cpp b/comfortable-swipe.cpp
index c49baf0..a11b232 100644
--- a/comfortable-swipe.cpp
+++ b/comfortable-swipe.cpp
@@ -54,6 +54,9 @@ int main(int argc, char** args)
else if (arg == "debug")
comfortable_swipe::service::debug();
+ else if (arg == "status")
+ comfortable_swipe::service::status();
+
else /* if (arg == "help") */
comfortable_swipe::service::help();
}
diff --git a/lib/comfortable_swipe b/lib/comfortable_swipe
index 3316ca4..ce75197 100644
--- a/lib/comfortable_swipe
+++ b/lib/comfortable_swipe
@@ -34,6 +34,7 @@ along with this program. If not, see .
#include "service/help.cpp"
#include "service/restart.cpp"
#include "service/start.cpp"
+#include "service/status.cpp"
#include "service/stop.cpp"
#include "util/autostart_filename.cpp"
#include "util/conf_filename.cpp"
diff --git a/lib/index.hpp b/lib/index.hpp
index 21a36a7..35e1482 100644
--- a/lib/index.hpp
+++ b/lib/index.hpp
@@ -54,6 +54,7 @@ extern "C"
void help();
void restart();
void start();
+ void status();
void stop();
}
}
diff --git a/lib/service/help.cpp b/lib/service/help.cpp
index e1355e6..6514f24 100644
--- a/lib/service/help.cpp
+++ b/lib/service/help.cpp
@@ -39,6 +39,7 @@ namespace comfortable_swipe::service
std::puts("buffer - parses output of libinput debug-events");
std::puts("help - shows the help dialog");
std::puts("debug - logs raw output from input events taken from libinput");
+ std::puts("status - checks status of program and autostart");
std::puts("");
std::printf("Configuration file can be found in %s\n", conf_filename());
}
diff --git a/lib/service/status.cpp b/lib/service/status.cpp
new file mode 100644
index 0000000..7894e76
--- /dev/null
+++ b/lib/service/status.cpp
@@ -0,0 +1,58 @@
+#ifndef __COMFORTABLE_SWIPE__service_status__
+#define __COMFORTABLE_SWIPE__service_status__
+
+/*
+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 .
+*/
+
+#include "../index.hpp"
+#include // std::runtime_error
+#include // popen, pclose, getpid, access, F_OK
+#include // std::unique_ptr
+#include // std::array
+#include // std::atoi
+#include // FILE, std::feof, std::fgets, std::printf
+
+namespace comfortable_swipe::service
+{
+ /**
+ * Restarts the comfortable-swipe service.
+ */
+ void status()
+ {
+ // check if comfortable-swipe is running
+ bool running = false;
+ std::array buffer;
+ std::unique_ptr pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
+ if (pipe && !std::feof(pipe.get()) && std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL)
+ {
+ int pid = std::atoi(buffer.data());
+ if (pid != getpid())
+ running = true;
+ }
+
+ // check if autostart is on
+ auto autostart_f = comfortable_swipe::util::autostart_filename();
+ bool autostart_on = access(autostart_f, F_OK) != -1;
+
+ // print status
+ std::printf("program is %s\n", running ? "ON" : "OFF");
+ std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
+ }
+}
+
+#endif /* __COMFORTABLE_SWIPE__service_restart__ */
diff --git a/lib/service/stop.cpp b/lib/service/stop.cpp
index 58ca30e..7469c69 100644
--- a/lib/service/stop.cpp
+++ b/lib/service/stop.cpp
@@ -26,6 +26,7 @@ along with this program. If not, see .
#include // popen, pclose, getpid
#include // std::unique_ptr
#include // std::array
+#include // std::atoi
#include // FILE, std::feof, std::fgets
namespace comfortable_swipe::service