From 88524eea4c1499f352d790081388ed680412927e Mon Sep 17 00:00:00 2001 From: Lexi Quinn Date: Fri, 17 Sep 2021 07:14:35 +1000 Subject: [PATCH] Added hotkey to disable global hotkeys --- README.md | 18 ++++++++++-------- keys.c | 8 +++++++- keys.h | 2 ++ timer.c | 1 + 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ed337c7..7bc63a4 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -*Quinn's Utterly Elegant Speedrun Timer* -A speedrun timer for *nix terminals +# Quinn's Utterly Elegant Speedrun Timer -**Features** -Global hotkeys -24-bit terminal color -Human readable JSON splits file -Splits.io format compliance -60+ fps rendering +A speedrun timer for \*nix terminals + +## Features + +- Global hotkeys +- 24-bit terminal color +- Human readable JSON splits file +- Import splits from a Splits.io file +- High fps rendering diff --git a/keys.c b/keys.c index 7dc531a..cdc3857 100644 --- a/keys.c +++ b/keys.c @@ -1,5 +1,6 @@ #include "keys.h" +bool hotkeys_enabled = true; char buf; int pipefd[2]; struct keymap km; @@ -22,6 +23,8 @@ void dispatch_proc(uiohook_event * const event) { buf = K_SPLIT; if (event->data.keyboard.keycode == km.CLOSE) buf = K_CLOSE; + if (event->data.keyboard.keycode == km.HOTKS) + buf = K_HOTKS; write(pipefd[1], &buf, 1); default: break; @@ -30,7 +33,8 @@ void dispatch_proc(uiohook_event * const event) { int handleInput() { - if (read(pipefd[0], &buf, 1) == -1) + ssize_t rd = read(pipefd[0], &buf, 1); + if ((!hotkeys_enabled && buf != K_HOTKS) || rd == -1) return 0; if (buf == K_SPLIT) split(); @@ -40,6 +44,8 @@ int handleInput() stop(); if (buf == K_PAUSE) tpause(); + if (buf == K_HOTKS) + hotkeys_enabled = !hotkeys_enabled; if (buf == K_CLOSE) return 1; return 0; diff --git a/keys.h b/keys.h index 36ee64b..2599d23 100644 --- a/keys.h +++ b/keys.h @@ -10,6 +10,7 @@ #define K_PAUSE 3 #define K_SPLIT 4 #define K_CLOSE 5 +#define K_HOTKS 6 struct keymap { @@ -18,6 +19,7 @@ struct keymap uint16_t PAUSE; uint16_t SPLIT; uint16_t CLOSE; + uint16_t HOTKS; }; extern char buf; diff --git a/timer.c b/timer.c index 4c4a425..1885044 100644 --- a/timer.c +++ b/timer.c @@ -124,6 +124,7 @@ void loadKeymap() km.PAUSE = VC_D; km.SPLIT = VC_E; km.CLOSE = VC_C; + km.HOTKS = VC_T; //char path[256]; //strcat(strcpy(path, getenv("HOME")), "/.config/qtimer"); //mkdir(path, 0777);