diff --git a/Makefile b/Makefile index f665025..feee254 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ BINARY_STATS = keystroke-stats SERVICE = keystats.service SYSTEMD_USER = /usr/lib/systemd/user -.PHONY: all build install uninstall status logs clean +.PHONY: all build install uninstall status logs clean setup all: build @@ -12,7 +12,10 @@ build: cmake -S . -B build cmake --build build -install: build +setup: + sudo usermod -aG input $(USER) + +install: build setup sudo cp build/$(BINARY_DAEMON) $(PREFIX)/bin/$(BINARY_DAEMON) sudo cp build/$(BINARY_STATS) $(PREFIX)/bin/$(BINARY_STATS) sudo cp $(SERVICE) $(SYSTEMD_USER)/$(SERVICE) diff --git a/main.cpp b/main.cpp index 91b7332..425358b 100644 --- a/main.cpp +++ b/main.cpp @@ -13,7 +13,7 @@ #include #include -// ─── Key name map ───────────────────────────────────────────────────────────── + std::unordered_map keyNames = { {KEY_ESC, "Esc"}, {KEY_F1, "F1"}, {KEY_F2, "F2"}, {KEY_F3, "F3"}, @@ -49,13 +49,11 @@ std::unordered_map keyNames = { {KEY_KPDOT, "KP."}, {KEY_KPENTER, "KPEnter"}, }; -// ─── Globals ────────────────────────────────────────────────────────────────── - std::unordered_map keyCounts; sqlite3* db = nullptr; int fd = -1; -// ─── DB ─────────────────────────────────────────────────────────────────────── + void initDB() { struct passwd* pw = getpwuid(getuid()); @@ -150,7 +148,7 @@ void flushDailyToDB(int code, long long count) { sqlite3_step(stmt); sqlite3_finalize(stmt); } -// ─── Device ─────────────────────────────────────────────────────────────────── + std::string findKeyboard() { DIR* dir = opendir("/dev/input"); @@ -192,7 +190,7 @@ std::string findKeyboard() { return found; } -// ─── Signal handler ─────────────────────────────────────────────────────────── + void onExit(int) { flushToDB(); @@ -201,7 +199,7 @@ void onExit(int) { exit(0); } -// ─── Main ───────────────────────────────────────────────────────────────────── + int main() { signal(SIGINT, onExit); diff --git a/stats.cpp b/stats.cpp index c6bb861..ef3f9a7 100644 --- a/stats.cpp +++ b/stats.cpp @@ -124,7 +124,6 @@ Element renderStats(const std::vector& stats, const std::vector rows; for (auto& row : keyboardLayout) { std::vector keys; @@ -136,7 +135,7 @@ Element renderStats(const std::vector& stats, const std::vector topList; int limit = std::min((int)stats.size(), 10); for (int i = 0; i < limit; i++) { @@ -152,7 +151,6 @@ Element renderStats(const std::vector& stats, const std::vector todayList; int todayLimit = std::min((int)todayStats.size(), 5); @@ -172,7 +170,7 @@ Element renderStats(const std::vector& stats, const std::vector