sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit c98f864e5e2532085fd5d44d5b3477a71004c4c7
parent e8b611564e663747d6d829394160fdf8f17ae157
Author: levi0x0 <levi0x0x@gmail.com>
Date:   Mon, 23 Feb 2015 19:31:27 +0200

barM - the new BarMonitor.

Diffstat:
Adwm.suckless.org/dwmstatus/barM.c | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ddwm.suckless.org/dwmstatus/bar_monitor.c | 296-------------------------------------------------------------------------------
Mdwm.suckless.org/dwmstatus/index.md | 2+-
3 files changed, 95 insertions(+), 297 deletions(-)

diff --git a/dwm.suckless.org/dwmstatus/barM.c b/dwm.suckless.org/dwmstatus/barM.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014,2015 levi0x0 + * + * barM (bar_monitor or BarMonitor) is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This is a new version of bar monitor, less lines of code more effective. + * + * Read main() to configure your new status Bar. + * + * compile: gcc -o barM barM.c -lX11 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <string.h> +#include <X11/Xlib.h> + +#define VERSION "0.10" +#define TIME_FORMAT " (%H:%M) (%d-%m-%Y)" +#define MAXSTR 1024 + +char * TimeADate(void) { + static char buffer[MAXSTR]; + + /* get time*/ + time_t now = time(0); + + + /* Read the time by the foramt*/ + strftime(buffer, MAXSTR, TIME_FORMAT, localtime(&now)); + + /* Return the buffer content*/ + return buffer; +} + + +char * spawn(char *c) { + FILE *proc; + static char buffer[MAXSTR]; + + if ((proc = popen(c, "r")) == NULL ) { + fprintf(stderr, "[barM] Failed to execute the command.\n"); + exit(1);; + } + + fscanf(proc, "%[^\n]", buffer); + pclose(proc); + + return buffer; +} + + +void XSetRoot(char *name) { + Display *display; + + /* try open 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(int argc, char **argv) { + char status[MAXSTR]; + + /*append here your commands for the spawn function*/ + char *ram = spawn("free -mh | awk 'NR==2{print $3\"/\"$2}'"); + + /* Examples: + char *battery = spawn("/sys/class/power_supply/BAT1/capacity"); + char *uname = spawn("uname"); + char * battery_status= spawn("/sys/class/power_supply/BAT1/status"); + + + XXX: DONT! forget to add the varibale to sprintf() + */ + + sprintf(status, "(%s) %s", ram, TimeADate()); + XSetRoot(status); + + /*sleep function*/ + sleep(1); + + return 0; +} diff --git a/dwm.suckless.org/dwmstatus/bar_monitor.c b/dwm.suckless.org/dwmstatus/bar_monitor.c @@ -1,296 +0,0 @@ -/* - * bar_monitor.c - another version of dwmstatus. - * - * Author: levi0x0 - * - * - * - * if you Want to write new fucntion to bar_monitor please do so! - * and let me know (: - * - * - * XXX: - * IN VERSION 0.9/10 I DIDN'T CHECKED bar_monitor ON a LAPTOP - * IF YOU FOUND ANY BUGS PLEASE LET ME KNOW! - * - *----------- - * News: - *----------- - * 13-11-2014 - version 0.10 added utsname options - *-------------------------------------------------------- - * - * 07-11-2014 - What's New in Version 0.9? - * - * 1) Check Mail function for gmail using libcurl! - * 2) a Laptop Support - * 3) Porto options - * 4) Many Features has been added - * - * And many more! - * - *--------------------------------------------------------- - * ChangeLog: - * ------------ - * 13/11/2014, - 0.10 - * 07/11/2014, - 0.9 - * 13/09/2014, - 0.8 - * 08/08/2014, - 0.7 - * 19/07/2014, - 0.3 - * 02/07/2014, - 0.1 - * - * - * ----------- - * Usage - * ---------- - * .xinitrc: - * - * while [ true ];do - * $(bar_monitor) - * done & - * - * bar_monitor contain sleep(1) function. - * - *-------------- - * Compile - *-------------- - * - * Compile: - * gcc bar_monitor.c -o bar_monitor -lX11 - * - * Compile with CHECK_GMAIL_FUNCTION: - * gcc bar_monitor.c -o bar_monitor -lX11 -lcurl - */ - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <string.h> -#include <X11/Xlib.h> -#include <sys/utsname.h> - -/* globals*/ -#define VERSION "0.9" -#define TIME_FORMAT "%H:%M (%d/%m/%Y)" -#define MEXSTR 1024 -#define CHECK_GMAIL_MAIL 0 -#define SHOW_MACHINE 0 -#define SHOW_KERNEL 1 -#define SHOW_NODENAME 0 - -/* Laptop config*/ -#define LAPTOP 0 - -#if LAPTOP - #define TEMP_FILE "/sys/class/hwmon/hwmon0/temp1_input" - - /* BAT1 or BAT0 change if needed*/ - #define CAPACITY_FILE "/sys/class/power_supply/BAT1/capacity" - #define BATTERY_STATUS_FILE "/sys/class/power_supply/BAT1/status" - char status_linecp[MEXSTR]; - - /* Functions prototypes*/ - char * ReadBatteryStat(void); - int ReadBatteryCap(void); - int ReadTemp(void); - -#endif - -/* include libcurl and gmail stuff*/ -#if CHECK_GMAIL_MAIL - #include <curl/curl.h> - #define CURL_VERBOSE 0 - static char * GMAIL_MAIL_FEED = "https://mail.google.com/mail/feed/atom"; - static char * GMAIL_MAIL_USER = "USERNAME"; - static char * GMAIL_MAIL_PASSWORD = "PASSWORD"; - static char * USER_AGENT = "Mozilla/5.0 (X11; Linux; rv:0.0) Mail Reader BarMon "VERSION; - - /* Functions prototypes*/ - int CheckGmail(void); -#endif - -/* Variables */ -static char buffer[MEXSTR]; -static char data_size[MEXSTR]; -static char UNnamebuffer[MEXSTR]; - -/* functions prototypes */ -char * TimeADate(void); -void XSetRoot(char *); - -int main(int argc, char **argv) { - char status[MEXSTR]; - int Newmail = 0; - struct utsname s; - - #if CHECK_GMAIL_MAIL - CheckGmail(); - /* 348 can be change by the size of your email address, - * you can check the size of the curl_buffer and change it*/ - if ( strlen(data_size) > 348 ) - Newmail = 1; - else - Newmail = 0; - #endif - uname(&s); - - #if SHOW_KERNEL - strcat(UNnamebuffer, s.release); - #elif SHOW_MACHINE - strcat(UNnamebuffer, s.machine); - #elif SHOW_NODENAME - strcat(UNnamebuffer, s.nodename); - #elif SHOW_SYSNAME - strcat(UNnamebuffer, s.sysname); - #else - strcat(UNnamebuffer, s.nodename); - #endif - - #if LAPTOP - sprintf(status, "(%s) (%dc) ( %d%%, %s ) (%d) %s", UNnamebuffer, ReadTemp(), ReadBatteryCap(), - ReadBatteryStat(), Newmail, TimeADate()); - XSetRoot(status); - #else - sprintf(status, "(%s) (%d) %s", UNnamebuffer, Newmail, TimeADate()); - XSetRoot(status); - #endif - - - - sleep(1); - - return 0; -} - -char * TimeADate(void) { - /* get time*/ - time_t now = time(0); - - - /* Read the time by the foramt*/ - strftime(buffer, MEXSTR, TIME_FORMAT, localtime(&now)); - - /* Return the buffer content*/ - return buffer; -} - - -void XSetRoot(char *name) { - Display *display; - - /* try open display*/ - if (( display = XOpenDisplay(0x0)) == NULL ) { - fprintf(stderr, "[BarMon] Oh NO! Cannot open display!\n"); - exit(1); - } - - /* set window name*/ - XStoreName(display, DefaultRootWindow(display), name); - XSync(display, 0); - - /* close display*/ - XCloseDisplay(display); -} - - -void * WriteBackData(void *ptr, size_t nmemb, size_t size, void *stream) { - strncpy(data_size, ptr, MEXSTR); -} - -#if CHECK_GMAIL_MAIL - int CheckGmail(void) { - CURL *curl_handler; - CURLcode r; - - - /* init curl*/ - curl_handler = curl_easy_init(); - - - /* start*/ - - if ( curl_handler ) { - /* feed url*/ - curl_easy_setopt(curl_handler, CURLOPT_URL, GMAIL_MAIL_FEED); - - /* login det*/ - curl_easy_setopt(curl_handler, CURLOPT_USERNAME, GMAIL_MAIL_USER); - curl_easy_setopt(curl_handler, CURLOPT_PASSWORD, GMAIL_MAIL_PASSWORD); - - /* USER Agent*/ - curl_easy_setopt(curl_handler, CURLOPT_USERAGENT , USER_AGENT); - - /* SSL*/ - curl_easy_setopt(curl_handler, CURLOPT_SSL_VERIFYPEER, 1); - curl_easy_setopt(curl_handler, CURLOPT_SSL_VERIFYHOST, 1); - curl_easy_setopt(curl_handler, CURLOPT_VERBOSE, CURL_VERBOSE); - - /* write back function*/ - curl_easy_setopt(curl_handler, CURLOPT_WRITEFUNCTION, WriteBackData); - } - - curl_easy_perform(curl_handler); - curl_easy_cleanup(curl_handler); - - } -#endif - - -#if LAPTOP - /* read the temp*/ - int ReadTemp(void) { - FILE *t_file; - int ret = 0; - - - if (( t_file = fopen(TEMP_FILE, "rt")) == NULL) { - fprintf(stderr, "Failed to open: %s\n", TEMP_FILE); - exit(1); - } - - fscanf(t_file, "%d", &ret); - - return ret / 1000; - } - - - - int ReadBatteryCap(void) { - int capacity = 0; - FILE *fp; - - if (( fp = fopen(CAPACITY_FILE, "r")) == NULL ){ - fprintf(stderr, "Failed to open: %s\n", CAPACITY_FILE); - exit(EXIT_FAILURE); - } - - fscanf(fp, "%d", &capacity); - fclose(fp); - - return capacity; - } - - - char * ReadBatteryStat(void) { - FILE *status_file; - char *line = NULL; - size_t len = 0; - ssize_t read; - - if (( status_file = fopen(BATTERY_STATUS_FILE, "rt")) == NULL ) { - fprintf(stderr, "Failed to open: %s\n", BATTERY_STATUS_FILE); - exit(EXIT_FAILURE); - } - - while (( read = getline(&line, &len, status_file)) != -1 ) { - ; - } - - strncpy(status_linecp, line, strlen(line)); - - strtok(status_linecp, "\n"); - free(line); - - return status_linecp; - } - -#endif diff --git a/dwm.suckless.org/dwmstatus/index.md b/dwm.suckless.org/dwmstatus/index.md @@ -24,7 +24,7 @@ Please add your own version of dwmstatus here. * [suspend-statusbar.c](suspend-statusbar.c) - loadavg, wifi, battery and date. If battery goes below threshold - run suspend command * [gods](https://github.com/schachmat/gods) - implemented in Go. prints network speed, cpu, ram, date/time * [go-dwmstatus](https://github.com/oniichaNj/go-dwmstatus) - A Go bar that prints current MPD song, load averages, time/date and battery percentage. -* [BarMonitor](bar_monitor.c) - displays, battery status, date/time, temperature, check mail function. +* [barM](barM.c) - can display all, time/date, ram usage, output of commands (the New BarMonitor). Helper functions ----------------