From ac2594dc0f02d08bef0cd1fb4082143e18055865 Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Sat, 20 Jul 2019 19:09:20 -0700 Subject: [PATCH] dwm status line and lame script --- bruh | 8 +++ dwm-stat/.gitignore | 1 + dwm-stat/Makefile | 8 +++ dwm-stat/status.c | 123 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100755 bruh create mode 100644 dwm-stat/.gitignore create mode 100644 dwm-stat/Makefile create mode 100644 dwm-stat/status.c diff --git a/bruh b/bruh new file mode 100755 index 0000000..32ce003 --- /dev/null +++ b/bruh @@ -0,0 +1,8 @@ +#!/bin/sh +# This is only here because my xserver is rarted +# in other words i setup my own rice every login by hand :( +newbg +bright 60 +compton -b + + diff --git a/dwm-stat/.gitignore b/dwm-stat/.gitignore new file mode 100644 index 0000000..ecd951a --- /dev/null +++ b/dwm-stat/.gitignore @@ -0,0 +1 @@ +statline diff --git a/dwm-stat/Makefile b/dwm-stat/Makefile new file mode 100644 index 0000000..87d0b39 --- /dev/null +++ b/dwm-stat/Makefile @@ -0,0 +1,8 @@ +stat: + gcc -o statline status.c -O2 -s -lX11 + +clean: + rm -f statline + +install: + ln -s $(shell pwd)/statline /usr/bin/statline diff --git a/dwm-stat/status.c b/dwm-stat/status.c new file mode 100644 index 0000000..bce3cbb --- /dev/null +++ b/dwm-stat/status.c @@ -0,0 +1,123 @@ +// statline by shockrah +// Inspired by barM +// barM is a great tool but formats information in a really ugly fashion +// This version mainly aims to ve a visual overhaul of both code and output over barM +// Dependancies: cat grep awk + +// Define these however you like +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BASIC_MSG "/comfy/ o clock | " +#define TIME_FORMAT "%I:%M%p - %d %b %Y" + +#define TIME_DELAY 3 +#define MAXSTR 1024 + +#define MEM_BREAD_SIZE 32 +#define STD_IO + +// `man date` should give you some more info on what the format specs do +// This format give the form ยป 05:13 PM - 20 Jul 2019 +static char* +date_time(void) +{ + static char date[MAXSTR]; + time_t now = time(0); + + strftime(date, sizeof(date), TIME_FORMAT, localtime(&now)); + return date; +} + +char* +ram_usage(void) +{ + struct sysinfo info; + sysinfo(&info); + static char buf[MAXSTR]; + long sum; + + // TODO: fix the Lazily reading through /proc/meminfo + FILE* res = popen("cat /proc/meminfo | grep -e ^Cached -e Buffers -e Slab | awk '{print $2}'", "r"); + if(res) { + sum = 0; + while(fgets(buf, sizeof(buf)-1, res) != NULL) { + sum += atoi(buf); + } + sum *= 1000; // KB to B + } + double used = (info.totalram - info.freeram - sum) / 1000000000.; + double total = info.totalram / 1000000000.; + + snprintf(buf, sizeof(buf), "%.2f G/ %.1f G", used, total); + return buf; +} + +static char* +cpu_usage(void) +{ + return "CPU Usage Placeholder"; +} + +static void +XSetRoot(char* name) +{ + Display *display; + + if (( display = XOpenDisplay(0x0)) == NULL ) { + fprintf(stderr, "[barM] cannot open display!\n"); + exit(1); + } + + XStoreName(display, DefaultRootWindow(display), name); + XSync(display, 0); + + XCloseDisplay(display); +} + +int +main(void) +{ + // Here you can put the functions you create as they should be executed from here + static char* (*func_table[])(void) = { + ram_usage, + date_time, + }; + + char stat_output[MAXSTR]; + // First things that don't need updating like ever + int base_len = snprintf(stat_output, sizeof(stat_output), BASIC_MSG); + char* base_offset = stat_output + base_len; + + // Make sure we didn't go past the end of our buffer + if(base_offset >= sizeof(stat_output)+stat_output) { + XSetRoot(stat_output); + return 1; + } + // Now the regularly updated stuff like date/time cpu usage etc. + int len; + for(;;) { + int remainder = sizeof(stat_output) - base_len; // starting position for 'dynamic text' + char* tmp_base_ptr = base_offset; + for(int i = 0; i < sizeof(func_table)/sizeof(func_table[0]); ++i) { + if(tmp_base_ptr > (stat_output+MAXSTR)) { + break; + } + + int written = snprintf(tmp_base_ptr, remainder, "%s | ", func_table[i]()); + tmp_base_ptr += written; + remainder -= written; + } + + XSetRoot(stat_output); + sleep(TIME_DELAY); + } + return 0; +}