commit f123e56892f058174b86d5188999e6d6a09dad50
parent a7082d30d7e243878b138866df4c4cc78e4ea45a
Author: awy <awy@awy.one>
Date: Wed, 12 Nov 2025 19:00:17 +0300
all other buttons
Diffstat:
| M | blocks.def.h | | | 6 | +++--- |
| M | someblocks.c | | | 83 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ |
2 files changed, 74 insertions(+), 15 deletions(-)
diff --git a/blocks.def.h b/blocks.def.h
@@ -1,8 +1,8 @@
//Modify this file to change what commands output to your statusbar, and recompile using the make command.
static const Block blocks[] = {
- /*Icon*/ /*Command*/ /*Update Interval*/ /*Update Signal*/ /*Left Click*/
- {"", "date", 1, 0, "foot -e calcurse"},
- {"", "echo something", 20, 0, "notify-send wow"},
+ /*Icon*/ /*Command*/ /*Update Interval*/ /*Update Signal*/ /*Left Click*/ /*Right Click*/ /*Middle Click*/ /*Scroll Up*/ /*Scroll Down*/
+ {"", "date", 1, 0, "foot -e calcurse", "notify-send firstblock", NULL, NULL, NULL},
+ {"", "echo something", 20, 0, "foot -e btop", "notify-send secondblock", NULL, NULL, NULL},
};
diff --git a/someblocks.c b/someblocks.c
@@ -17,7 +17,7 @@
#define SIGMINUS SIGRTMIN
#endif
#define LENGTH(X) (sizeof (X) / sizeof (X[0]))
-#define CMDLENGTH 150
+#define CMDLENGTH 512
#define MIN(a, b) ((a < b) ? a : b)
#define STATUSLENGTH (LENGTH (blocks) * CMDLENGTH + 1)
@@ -28,6 +28,10 @@ typedef struct
unsigned int interval;
unsigned int signal;
char *lclick;
+ char *rclick;
+ char *mclick;
+ char *upscroll;
+ char *downscroll;
} Block;
#ifndef __OpenBSD__
void dummysighandler (int num);
@@ -61,24 +65,79 @@ getcmd (const Block *block, char *output)
FILE *cmdf = popen (block->command, "r");
if (!cmdf)
return;
+
fgets (tmp, sizeof (tmp) - delimLen, cmdf);
pclose (cmdf);
int len = strlen (tmp);
- if (len == 0)
- return;
- if (tmp[len - 1] == '\n')
+ if (len && tmp[len - 1] == '\n')
tmp[len - 1] = '\0';
- // Add your clickable markup here
- if (block->lclick)
- snprintf (output, CMDLENGTH, "^lm(sh -c '%s')%s%s^lm()", block->lclick,
- block->icon ? block->icon : "", tmp);
- else
- snprintf (output, CMDLENGTH, "%s%s", block->icon ? block->icon : "", tmp);
+ // Start mouse tags
+ char start_tags[512] = ""; // larger buffer for multiple buttons
+ char end_tags[128] = "";
+
+ if (block->lclick && block->lclick[0] != '\0')
+ {
+ strncat (start_tags, "^lm(sh -c '",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, block->lclick,
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, "')",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (end_tags, "^lm()", sizeof (end_tags) - strlen (end_tags) - 1);
+ }
+
+ if (block->rclick && block->rclick[0] != '\0')
+ {
+ strncat (start_tags, "^rm(sh -c '",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, block->rclick,
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, "')",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (end_tags, "^rm()", sizeof (end_tags) - strlen (end_tags) - 1);
+ }
+
+ if (block->mclick && block->mclick[0] != '\0')
+ {
+ strncat (start_tags, "^mm(sh -c '",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, block->mclick,
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, "')",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (end_tags, "^mm()", sizeof (end_tags) - strlen (end_tags) - 1);
+ }
+
+ if (block->upscroll && block->upscroll[0] != '\0')
+ {
+ strncat (start_tags, "^us(sh -c '",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, block->upscroll,
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, "')",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (end_tags, "^us()", sizeof (end_tags) - strlen (end_tags) - 1);
+ }
+
+ if (block->downscroll && block->downscroll[0] != '\0')
+ {
+ strncat (start_tags, "^ds(sh -c '",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, block->downscroll,
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (start_tags, "')",
+ sizeof (start_tags) - strlen (start_tags) - 1);
+ strncat (end_tags, "^ds()", sizeof (end_tags) - strlen (end_tags) - 1);
+ }
+
+ // Compose final output
+ snprintf (output, CMDLENGTH, "%s%s%s%s", start_tags,
+ block->icon ? block->icon : "", tmp, end_tags);
- // Add delimiter
- strncat (output, delim, delimLen);
+ // Add delimiter safely
+ strncat (output, delim, CMDLENGTH - strlen (output) - 1);
}
void