From 3e6a7d369b880413c1d9679fb7677e878fdbb45a Mon Sep 17 00:00:00 2001 From: awy Date: Sat, 13 Sep 2025 12:59:29 +0300 Subject: updates --- src/stmemory.c | 34 ++++++++++++++++++++++++++++++++++ src/stmusic.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/sttorrent.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) (limited to 'src') diff --git a/src/stmemory.c b/src/stmemory.c index 4f1435a..863d9fc 100644 --- a/src/stmemory.c +++ b/src/stmemory.c @@ -15,9 +15,41 @@ . */ #include +#include #include "../lib/util.h" +void +buttonhandler() +{ + char *term; + char *env; + int button; + + button = 0; + if ((env = getenv("BLOCK_BUTTON"))) + button = getbtnint(env); + + if (!(term = getenv("TERMINAL"))) + term = "footclient"; + + const char *termcmd[] = { term, "-e", "btop", NULL }; + + switch (button) { + case 1: + break; + case 2: + spawn(termcmd); + break; + case 3: + sendnotif("stmemory", " Memory module", + "- Shows Memory Used.\n- Click to show memory hogs.\n\ +- Middle click to open btop."); + break; + default: break; + } +} + int main(void) { @@ -25,6 +57,8 @@ main(void) char line[256]; long total, free; + buttonhandler(); + if (!(fp = fopen("/proc/meminfo", "r"))) die("failed to open: /proc/meminfo"); diff --git a/src/stmusic.c b/src/stmusic.c index 46d7059..ac81de1 100644 --- a/src/stmusic.c +++ b/src/stmusic.c @@ -16,6 +16,59 @@ #include #include +#include + +#include "../lib/util.h" + +void +buttonhandler() +{ + char *term; + char *env; + int button; + + button = 0; + if ((env = getenv("BLOCK_BUTTON"))) + button = getbtnint(env); + + if (!(term = getenv("TERMINAL"))) + term = "footclient"; + + const char *rmpc[] = { term, "-e", "rmpc", NULL }; + const char *toggle[] = { "rmpc", "togglepause", NULL }; + const char *prev[] = { "rmpc", "prev", NULL }; + const char *next[] = { "rmpc", "next", NULL }; + + switch (button) { + case 1: + spawn(rmpc); + break; + case 2: + spawn(toggle); + break; + case 3: + sendnotif("stmusic", " Music module", + "- Shows mpd song playing.\n\ +-  paused.\n\ +-  repeat mode.\n\ +-  shuffle mode.\n\ +- 󰮯 consume mode.\n\ +- 󰮯 󰇊 consume oneshot mode.\n\ +- 󰎤 single mode.\n\ +- 󰇊 single oneshot mode.\n\ +- Left click opens rmpc.\n\ +- Middle click pauses.\n\ +- Scroll changes track."); + break; + case 4: + spawn(prev); + break; + case 5: + spawn(next); + break; + default: break; + } +} int main(void) @@ -24,6 +77,8 @@ main(void) struct mpd_status *status; struct mpd_song *song; + buttonhandler(); + /* Connect to MPD (default: localhost:6600) */ conn = mpd_connection_new(NULL, 0, 30000); if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { diff --git a/src/sttorrent.c b/src/sttorrent.c index 3bd513f..b1a62d1 100644 --- a/src/sttorrent.c +++ b/src/sttorrent.c @@ -18,7 +18,42 @@ #include #include #include + #include "../lib/cjson/cJSON.h" +#include "../lib/util.h" + +void +buttonhandler() +{ + char *term; + char *env; + int button; + + button = 0; + if ((env = getenv("BLOCK_BUTTON"))) + button = getbtnint(env); + + if (!(term = getenv("TERMINAL"))) + term = "footclient"; + + const char *stig[] = { term, "-e", "stig", NULL }; + const char *toggle[] = { "td-toggle", NULL }; + + switch (button) { + case 1: + spawn(stig); + break; + case 2: + spawn(toggle); + break; + case 3: + sendnotif("sttorrent", " Torrent module", + "- Left click to open stig.\n\ +- Middle click to toggle transmission."); + break; + default: break; + } +} struct MemoryStruct { char *memory; @@ -102,6 +137,8 @@ main(void) struct curl_slist *headers = NULL; const char *json = "{\"method\":\"torrent-get\",\"arguments\":{\"fields\":[\"status\", \"percentDone\"]}}"; + buttonhandler(); + curl_global_init(CURL_GLOBAL_ALL); /* To get status from transmission we need to send two CURL requests, first one to obtain session id. */ -- cgit v1.2.3