Added hotkey to disable global hotkeys

This commit is contained in:
Lexi Quinn 2021-09-17 07:14:35 +10:00
parent dae9fe8a10
commit 88524eea4c
4 changed files with 20 additions and 9 deletions

View File

@ -1,9 +1,11 @@
*Quinn's Utterly Elegant Speedrun Timer* # Quinn's Utterly Elegant Speedrun Timer
A speedrun timer for *nix terminals
**Features** A speedrun timer for \*nix terminals
Global hotkeys
24-bit terminal color ## Features
Human readable JSON splits file
Splits.io format compliance - Global hotkeys
60+ fps rendering - 24-bit terminal color
- Human readable JSON splits file
- Import splits from a Splits.io file
- High fps rendering

8
keys.c
View File

@ -1,5 +1,6 @@
#include "keys.h" #include "keys.h"
bool hotkeys_enabled = true;
char buf; char buf;
int pipefd[2]; int pipefd[2];
struct keymap km; struct keymap km;
@ -22,6 +23,8 @@ void dispatch_proc(uiohook_event * const event) {
buf = K_SPLIT; buf = K_SPLIT;
if (event->data.keyboard.keycode == km.CLOSE) if (event->data.keyboard.keycode == km.CLOSE)
buf = K_CLOSE; buf = K_CLOSE;
if (event->data.keyboard.keycode == km.HOTKS)
buf = K_HOTKS;
write(pipefd[1], &buf, 1); write(pipefd[1], &buf, 1);
default: default:
break; break;
@ -30,7 +33,8 @@ void dispatch_proc(uiohook_event * const event) {
int handleInput() 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; return 0;
if (buf == K_SPLIT) if (buf == K_SPLIT)
split(); split();
@ -40,6 +44,8 @@ int handleInput()
stop(); stop();
if (buf == K_PAUSE) if (buf == K_PAUSE)
tpause(); tpause();
if (buf == K_HOTKS)
hotkeys_enabled = !hotkeys_enabled;
if (buf == K_CLOSE) if (buf == K_CLOSE)
return 1; return 1;
return 0; return 0;

2
keys.h
View File

@ -10,6 +10,7 @@
#define K_PAUSE 3 #define K_PAUSE 3
#define K_SPLIT 4 #define K_SPLIT 4
#define K_CLOSE 5 #define K_CLOSE 5
#define K_HOTKS 6
struct keymap struct keymap
{ {
@ -18,6 +19,7 @@ struct keymap
uint16_t PAUSE; uint16_t PAUSE;
uint16_t SPLIT; uint16_t SPLIT;
uint16_t CLOSE; uint16_t CLOSE;
uint16_t HOTKS;
}; };
extern char buf; extern char buf;

View File

@ -124,6 +124,7 @@ void loadKeymap()
km.PAUSE = VC_D; km.PAUSE = VC_D;
km.SPLIT = VC_E; km.SPLIT = VC_E;
km.CLOSE = VC_C; km.CLOSE = VC_C;
km.HOTKS = VC_T;
//char path[256]; //char path[256];
//strcat(strcpy(path, getenv("HOME")), "/.config/qtimer"); //strcat(strcpy(path, getenv("HOME")), "/.config/qtimer");
//mkdir(path, 0777); //mkdir(path, 0777);