sites

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

commit e43750e5d4efe6f7e2c6519bbca2fc589c5e16be
parent 14aa947dd28d033cf0895bc5b223fad2c75a0e1a
Author: wifiextender <wifiextender@bitmessage.ch>
Date:   Sun, 12 Apr 2015 02:46:12 +0000

Exchanged the dwm-bar.c link

Diffstat:
Ddwm.suckless.org/dwmstatus/dwm-bar.c | 180-------------------------------------------------------------------------------
Mdwm.suckless.org/dwmstatus/index.md | 4++--
2 files changed, 2 insertions(+), 182 deletions(-)

diff --git a/dwm.suckless.org/dwmstatus/dwm-bar.c b/dwm.suckless.org/dwmstatus/dwm-bar.c @@ -1,179 +0,0 @@ -/* - dwm-bar.c - The `xsetroot' alternative in C to - set following information to the root window: - RAM 10%, SSD 10%, Linux release, Volume 10%, Time 10:00 PM - - Compile with: - gcc -Wall -Wextra -std=c99 -O2 dwm-bar.c -o $HOME/.cache/dwm-bar -lasound -lX11 - - Copyright 02/22/2015 Aaron Caffrey https://github.com/wifiextender - - This program 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 program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - MA 02110-1301, USA. -*/ - -#include <time.h> -#include <stdio.h> -#include <stdlib.h> -#include <inttypes.h> - -#include <sys/statvfs.h> -#include <sys/sysinfo.h> -#include <sys/utsname.h> - -#include <X11/Xlib.h> -#include <alsa/asoundlib.h> - -#define MB 1048576 -#define GB 1073741824 -#define VLA 100 -#define COMMA ',' - -static void get_ram(char *); -static void get_ssd(char *); -static void get_kernel(char *); -static void get_time(char *); -static void get_volume(char *); -static void set_status(const char *); - - -int main(void) -{ - char ram[VLA], ssd[VLA], kern[VLA]; - char volume[VLA], Time[VLA], combine[VLA*5]; - - get_ram(ram); - get_ssd(ssd); - get_kernel(kern); - get_volume(volume); - get_time(Time); - - sprintf(combine, - "%s %s%%%c %s %s%%%c %s%c %s %s%%%c %s %s", - "RAM", ram, COMMA, - "SSD", ssd, COMMA, - kern, COMMA, - "Volume", volume, COMMA, - "Time", Time); - - set_status(combine); - - return EXIT_SUCCESS; -} - - -static void get_ram(char *str1) -{ - uintmax_t used = 0, total = 0, percent = 0; - - struct sysinfo mem; - sysinfo(&mem); - - total = (uintmax_t) mem.totalram / MB; - used = (uintmax_t) (mem.totalram - mem.freeram - - mem.bufferram - mem.sharedram) / MB; - percent = (used * 100) / total; - - sprintf(str1, "%"PRIuMAX, percent); -} - - -static void get_ssd(char *str1) -{ - uintmax_t percent = 0; - - struct statvfs ssd; - statvfs(getenv("HOME"), &ssd); - - percent = ((ssd.f_blocks - ssd.f_bfree) * ssd.f_bsize) / GB; - - sprintf(str1, "%"PRIuMAX, percent); -} - - -static void get_kernel(char *str1) -{ - struct utsname KerneL; - uname(&KerneL); - - sprintf(str1, "%s %s", KerneL.sysname, KerneL.release); -} - - -static void get_time(char *str1) -{ - char time_str[VLA]; - - time_t t = time(NULL); - - strftime(time_str, VLA, "%I:%M %p", localtime(&t)); - - sprintf(str1, "%s", time_str); -} - - -static void get_volume(char *str1) -{ - snd_mixer_t *handle; - snd_mixer_elem_t *elem; - snd_mixer_selem_id_t *s_elem; - - snd_mixer_open(&handle, 0); - snd_mixer_attach(handle, "default"); - snd_mixer_selem_register(handle, NULL, NULL); - snd_mixer_load(handle); - snd_mixer_selem_id_malloc(&s_elem); - snd_mixer_selem_id_set_name(s_elem, "Master"); - - elem = snd_mixer_find_selem(handle, s_elem); - - if (elem == NULL) - { - snd_mixer_selem_id_free(s_elem); - snd_mixer_close(handle); - - exit(EXIT_FAILURE); - } - - long int vol, max, min, percent; - - snd_mixer_handle_events(handle); - snd_mixer_selem_get_playback_volume_range(elem, &min, &max); - snd_mixer_selem_get_playback_volume(elem, 0, &vol); - - percent = (vol * 100) / max; - - snd_mixer_selem_id_free(s_elem); - snd_mixer_close(handle); - - sprintf(str1, "%ld", percent); -} - - -static void set_status(const char *str1) -{ - Display *display = XOpenDisplay(NULL); - - if (display) - { - XStoreName(display, DefaultRootWindow(display), str1); - XSync(display, 0); - - XCloseDisplay(display); - } - - else - exit(EXIT_FAILURE); -}- \ No newline at end of file diff --git a/dwm.suckless.org/dwmstatus/index.md b/dwm.suckless.org/dwmstatus/index.md @@ -17,8 +17,9 @@ This is a barebone project you can use for changing it to your needs. User submitted versions ----------------------- -Please add your own version of dwmstatus here. +Please add your own version of dwmstatus here. +* [dwm-bar.c](https://github.com/wifiextender/dotfiles/blob/master/archlinux-openbsd/home/frost/.config/dwm_scripts/dwm-bar.c) - Display usage about: cpu, ram, disk, kernel, volume and time. I've wrote the code myself, so it is unique. * [dwmsd](https://github.com/johnko/dwmsd) - a daemon that listens on localhost tcp (may be useful as a base for asynchronous updates) * [profil-dwmstatus-1.0.c](profil-dwmstatus-1.0.c) - cpufreq, battery percent and date/time * [suspend-statusbar.c](suspend-statusbar.c) - loadavg, wifi, battery and date. If battery goes below threshold - run suspend command @@ -32,7 +33,6 @@ Helper functions If you have simple C functions for gathering system information, please add them here as file or as code example. -* [Get ram, disk, kernel, volume and time](dwm-bar.c) * [Support for ACPI battery status Linux](new-acpi-battery.c) * [Reading out a temperature from /sys](dwmstatus-temperature.c) * [Reading up-, and downspeeds of all network interfaces from /proc/net](dwmstatus-netusage.c)