summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2022-02-01 22:26:35 +0100
committerTom Smeding <tom@tomsmeding.com>2022-02-01 22:26:35 +0100
commite138113b1feb97200db61d3e26d4a550b6495078 (patch)
tree49ca9c6077c53102b9e8120d95ecae29261e4895
parentc0fc00d9ef108e932e187717da58c990b4cf4710 (diff)
Make trigger key (code-)configurable
-rw-r--r--main.cpp41
-rw-r--r--xutil.h1
2 files changed, 33 insertions, 9 deletions
diff --git a/main.cpp b/main.cpp
index f2d6a9a..5432ea2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,24 +1,43 @@
#include <iostream>
+#include <string>
#include <filesystem>
#include <cstring>
#include <X11/Xutil.h>
+#include <xkbcommon/xkbcommon-keysyms.h>
#include "seqmatcher.h"
#include "got.h"
#include "gui.h"
#include "xutil.h"
+namespace Config {
+ constexpr const char *const TRIGGER_KEY = "<F18>";
+ constexpr const char *const TRIGGER_KEY_DESCR = "F18 (XF86Launch9)";
+ constexpr const KeySym TRIGGER_KEY_X = XKB_KEY_XF86Launch9;
+
+ const std::string USAGE_TEXT = std::string{}
+ + " " + TRIGGER_KEY + " H -- Get brief help in a notification\n"
+ + " " + TRIGGER_KEY + " I -- Check into a sheet\n"
+ + " " + TRIGGER_KEY + " E -- Edit the note for the currently running activity\n"
+ + " " + TRIGGER_KEY + " O -- Check out of the current activity\n"
+ + " " + TRIGGER_KEY + " <space> -- Switch and check into the 'misc' sheet\n"
+ + " " + TRIGGER_KEY + " " + TRIGGER_KEY + " -- Show notification with current status\n"
+ + " " + TRIGGER_KEY + " Q -- Quit this program (killing it also works of course)\n";
+
+ const std::string USAGE_SUMMARY =
+ std::string{TRIGGER_KEY} + " + (H)elp (I)ncheck (O)utcheck (E)dit (Q)uit; "
+ + TRIGGER_KEY + " " + TRIGGER_KEY + " = status; "
+ + TRIGGER_KEY + " <space> = into misc";
+}
+
+
int main(int argc, char **argv) {
if (argc >= 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
std::cout <<
"GUI for GOT (https://github.com/lieuwex/got), which is a rewrite of Timetrap.\n"
- "This thing runs as a daemon; it gets activated with the Pause/Break key on\n"
+ "This thing runs as a daemon; it gets activated with the " << Config::TRIGGER_KEY_DESCR << " key on\n"
"your keyboard. The following sequences trigger actions:\n"
- " <break> E -- Edit the note for the currently running activity\n"
- " <break> I -- Check into a sheet\n"
- " <break> O -- Check out of the current activity\n"
- " <break> <space> -- Switch and check into the 'misc' sheet\n"
- " <break> Q -- Quit this program (killing it also works of course)\n"
+ << Config::USAGE_TEXT
<< std::flush;
return 0;
}
@@ -36,6 +55,10 @@ int main(int argc, char **argv) {
SeqMatcher matcher{dpy};
+ matcher.addSequence({XK_H}, []() {
+ gui::showNotification(Config::USAGE_SUMMARY);
+ });
+
matcher.addSequence({XK_E}, []() {
if (got::getRunning()) {
if (auto descr = gui::promptText("Edit currently running entry's text:")) {
@@ -76,14 +99,14 @@ int main(int argc, char **argv) {
gui::showNotification("Switched to 'misc'");
});
- matcher.addSequence({XK_Break}, []() {
+ matcher.addSequence({Config::TRIGGER_KEY_X}, []() {
auto current = got::getRunning();
if (!current) {
gui::showNotification("Currently checked out");
} else {
gui::showNotification(
"Checked into '" + current->first + "'" +
- (current->second.empty() ? current->second : " (" + current->second + ")")
+ (current->second.empty() ? "" : " (" + current->second + ")")
);
}
});
@@ -94,7 +117,7 @@ int main(int argc, char **argv) {
});
x::globalKeyWatch(
- dpy, XK_Break,
+ dpy, Config::TRIGGER_KEY_X,
[dpy, &matcher, &quitRequested](const XKeyEvent&) -> bool {
matcher.reset();
diff --git a/xutil.h b/xutil.h
index 337a190..03aa6cf 100644
--- a/xutil.h
+++ b/xutil.h
@@ -1,6 +1,7 @@
#pragma once
#include <functional>
+#include <optional>
#include <X11/Xlib.h>