updated makefile

This commit is contained in:
2026-03-15 23:49:15 +05:30
parent fa9a71541b
commit 2a37a1374d
3 changed files with 12 additions and 13 deletions
+5 -2
View File
@@ -4,7 +4,7 @@ BINARY_STATS = keystroke-stats
SERVICE = keystats.service SERVICE = keystats.service
SYSTEMD_USER = /usr/lib/systemd/user 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 all: build
@@ -12,7 +12,10 @@ build:
cmake -S . -B build cmake -S . -B build
cmake --build 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_DAEMON) $(PREFIX)/bin/$(BINARY_DAEMON)
sudo cp build/$(BINARY_STATS) $(PREFIX)/bin/$(BINARY_STATS) sudo cp build/$(BINARY_STATS) $(PREFIX)/bin/$(BINARY_STATS)
sudo cp $(SERVICE) $(SYSTEMD_USER)/$(SERVICE) sudo cp $(SERVICE) $(SYSTEMD_USER)/$(SERVICE)
+5 -7
View File
@@ -13,7 +13,7 @@
#include <unistd.h> #include <unistd.h>
#include <sqlite3.h> #include <sqlite3.h>
// ─── Key name map ─────────────────────────────────────────────────────────────
std::unordered_map<int, std::string> keyNames = { std::unordered_map<int, std::string> keyNames = {
{KEY_ESC, "Esc"}, {KEY_F1, "F1"}, {KEY_F2, "F2"}, {KEY_F3, "F3"}, {KEY_ESC, "Esc"}, {KEY_F1, "F1"}, {KEY_F2, "F2"}, {KEY_F3, "F3"},
@@ -49,13 +49,11 @@ std::unordered_map<int, std::string> keyNames = {
{KEY_KPDOT, "KP."}, {KEY_KPENTER, "KPEnter"}, {KEY_KPDOT, "KP."}, {KEY_KPENTER, "KPEnter"},
}; };
// ─── Globals ──────────────────────────────────────────────────────────────────
std::unordered_map<int, long long> keyCounts; std::unordered_map<int, long long> keyCounts;
sqlite3* db = nullptr; sqlite3* db = nullptr;
int fd = -1; int fd = -1;
// ─── DB ───────────────────────────────────────────────────────────────────────
void initDB() { void initDB() {
struct passwd* pw = getpwuid(getuid()); struct passwd* pw = getpwuid(getuid());
@@ -150,7 +148,7 @@ void flushDailyToDB(int code, long long count) {
sqlite3_step(stmt); sqlite3_step(stmt);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} }
// ─── Device ───────────────────────────────────────────────────────────────────
std::string findKeyboard() { std::string findKeyboard() {
DIR* dir = opendir("/dev/input"); DIR* dir = opendir("/dev/input");
@@ -192,7 +190,7 @@ std::string findKeyboard() {
return found; return found;
} }
// ─── Signal handler ───────────────────────────────────────────────────────────
void onExit(int) { void onExit(int) {
flushToDB(); flushToDB();
@@ -201,7 +199,7 @@ void onExit(int) {
exit(0); exit(0);
} }
// ─── Main ─────────────────────────────────────────────────────────────────────
int main() { int main() {
signal(SIGINT, onExit); signal(SIGINT, onExit);
+2 -4
View File
@@ -124,7 +124,6 @@ Element renderStats(const std::vector<KeyStat>& stats, const std::vector<KeyStat
long long maxCount = stats[0].count; long long maxCount = stats[0].count;
long long total = totalCount(stats); long long total = totalCount(stats);
// ── Heatmap ──────────────────────────────────────────────────────────────
std::vector<Element> rows; std::vector<Element> rows;
for (auto& row : keyboardLayout) { for (auto& row : keyboardLayout) {
std::vector<Element> keys; std::vector<Element> keys;
@@ -136,7 +135,7 @@ Element renderStats(const std::vector<KeyStat>& stats, const std::vector<KeyStat
rows.push_back(hbox(keys)); rows.push_back(hbox(keys));
} }
// ── Lifetime top 10 ──────────────────────────────────────────────────────
std::vector<Element> topList; std::vector<Element> topList;
int limit = std::min((int)stats.size(), 10); int limit = std::min((int)stats.size(), 10);
for (int i = 0; i < limit; i++) { for (int i = 0; i < limit; i++) {
@@ -152,7 +151,6 @@ Element renderStats(const std::vector<KeyStat>& stats, const std::vector<KeyStat
); );
} }
// ── Today top 5 ──────────────────────────────────────────────────────────
long long todayTotal = totalCount(todayStats); long long todayTotal = totalCount(todayStats);
std::vector<Element> todayList; std::vector<Element> todayList;
int todayLimit = std::min((int)todayStats.size(), 5); int todayLimit = std::min((int)todayStats.size(), 5);
@@ -172,7 +170,7 @@ Element renderStats(const std::vector<KeyStat>& stats, const std::vector<KeyStat
todayList.push_back(text("No keys pressed today yet.") | color(Color::GrayDark)); todayList.push_back(text("No keys pressed today yet.") | color(Color::GrayDark));
} }
// ── Legend ───────────────────────────────────────────────────────────────
auto legend = hbox({ auto legend = hbox({
text(" cold ") | color(Color::GrayDark), text(" cold ") | color(Color::GrayDark),
text("") | color(Color::Blue), text("") | color(Color::Blue),