diff options
author | awy <awy@awy.one> | 2025-09-13 12:59:29 +0300 |
---|---|---|
committer | awy <awy@awy.one> | 2025-09-13 12:59:29 +0300 |
commit | 3e6a7d369b880413c1d9679fb7677e878fdbb45a (patch) | |
tree | 03e3e1163335808816fe924cb329beb80eceb609 | |
parent | f45554776ae470a8b8764f3fe5c7c400e76839d6 (diff) | |
download | statusbar-3e6a7d369b880413c1d9679fb7677e878fdbb45a.tar.gz |
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | lib/util.h | 6 | ||||
-rw-r--r-- | src/stmemory.c | 34 | ||||
-rw-r--r-- | src/stmusic.c | 55 | ||||
-rw-r--r-- | src/sttorrent.c | 37 |
5 files changed, 136 insertions, 4 deletions
@@ -18,16 +18,16 @@ $(BINDIR): mkdir -p $(BINDIR) $(BINDIR)/stmusic: $(SRCDIR)/stmusic.c | $(BINDIR) - $(CC) $(CFLAGS) -o $@ $< -lmpdclient + $(CC) $(CFLAGS) $(NOTIFY_CFLAGS) -o $@ lib/util.c $< $(NOTIFY_LIBS) -lmpdclient $(BINDIR)/stmpdup: $(SRCDIR)/stmpdup.c | $(BINDIR) - $(CC) $(CFLAGS) -o $@ lib/util.c $< -lmpdclient + $(CC) $(CFLAGS) $(NOTIFY_CFLAGS) -o $@ lib/util.c $< $(NOTIFY_LIBS) -lmpdclient $(BINDIR)/sttorrent: $(SRCDIR)/sttorrent.c | $(BINDIR) - $(CC) $(CFLAGS) -o $@ lib/util.c lib/cjson/cJSON.c $< -lcurl + $(CC) $(CFLAGS) $(NOTIFY_CFLAGS) -o $@ lib/util.c lib/cjson/cJSON.c $< $(NOTIFY_LIBS) -lcurl $(BINDIR)/stweath: $(SRCDIR)/stweath.c | $(BINDIR) - $(CC) $(CFLAGS) -o $@ lib/util.c lib/cjson/cJSON.c $< -lcurl + $(CC) $(CFLAGS) $(NOTIFY_CFLAGS) -o $@ lib/util.c lib/cjson/cJSON.c $< $(NOTIFY_LIBS) -lcurl $(BINDIR)/%: $(SRCDIR)/%.c | $(BINDIR) $(CC) $(CFLAGS) $(NOTIFY_CFLAGS) -o $@ lib/util.c $< $(NOTIFY_LIBS) @@ -1,4 +1,10 @@ +#pragma once +#ifndef UTIL_H +#define UTIL_H + void die(const char *, ...); void sendnotif(const char *, const char *, const char *); int getbtnint(const char *blkbtn); void spawn(const char *const argv[]); + +#endif 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 @@ <https://www.gnu.org/licenses/>. */ #include <stdio.h> +#include <stdlib.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 *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 <mpd/client.h> #include <stdio.h> +#include <stdlib.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 *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 <stdio.h> #include <stdlib.h> #include <string.h> + #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. */ |