Skip to content

Commit

Permalink
gatotray 3.3 with memory chart
Browse files Browse the repository at this point in the history
  • Loading branch information
gatopeich committed Dec 15, 2017
1 parent 1cdcf37 commit 806f364
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 94 deletions.
7 changes: 4 additions & 3 deletions Debian-Control
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: gatotray
Version: 3.0
Version: 3.3
Section: Accessories
Priority: optional
Architecture: all
Essential: no
Depends: libgtk2.0-0
Pre-Depends:
Pre-Depends:
Recommends: xterm | procps | acpid
Suggests:
Suggests:
Installed-Size: 25
Maintainer: gatopeich <gatoguan-os@yahoo.com>
Conflicts:
Expand All @@ -16,3 +16,4 @@ Provides: gatotray
Description: gatotray is a tiny CPU monitor displaying several stats
graphically (usage, temperature, frequency) in small space,
and tight on resources.
It also contains a screensaver mode with Cairo vector rendering.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
# Briefly: Use it however suits you better and just give me due credit.
#
### Changelog:
# V3.3: Add free memory chart (from top)
# V3.2: Smooth Screensaver render with Cairo
# V3.1: Bugfixes. Versioning
# V3.0: Screensaver support.
# V2.1: Added CCby license. Restructured a bit.
# V2.0: Added 32-bit target for 64 bits environment.

VERSION := 3.2
CFLAGS := -std=c99 -Wall -O3 -g3 -DVERSION=\"$(VERSION)\" $(CFLAGS)
VERSION := 3.3
CFLAGS := -std=c99 -Wall -O2 -ggdb -DVERSION=\"$(VERSION)\" $(CFLAGS)
CPPFLAGS := `pkg-config --cflags gtk+-2.0` $(CPPFLAGS)
LDLIBS := `pkg-config --libs gtk+-2.0` $(LDLIBS)

Expand All @@ -38,6 +39,7 @@ gatotray-$(VERSION).deb: gatotray gatotray.xpm gatotray.desktop Debian-Control
install -vD gatotray.desktop root/usr/share/applications/gatotray.desktop
install -vD gatotray.xpm root/usr/share/icons/gatotray.xpm
install -vD Debian-Control root/DEBIAN/control
sed -i 's/^Version:.*/Version: $(VERSION)/' Debian-Control root/DEBIAN/control
dpkg -b root $@

# Additional: .api file for SciTE users...
Expand All @@ -55,7 +57,7 @@ clean:
rm -f $(objects) $(depends) $(targets)

%.o: %.c %.d
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<

%.i386: %.o.i386
$(LD) -m32 -o $@ $^
Expand Down
29 changes: 17 additions & 12 deletions cpu_usage.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* CPU usage and temperature functions.
*
*
* (c) 2011 by gatopeich, licensed under a Creative Commons Attribution 3.0
* Unported License: http://creativecommons.org/licenses/by/3.0/
* Briefly: Use it however suits you better and just give me due credit.
Expand Down Expand Up @@ -93,7 +93,7 @@ cpu_freq(void)

static FILE *cur_freq_file = NULL;
if (!cur_freq_file) {
cur_freq_file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq","r");
cur_freq_file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq","r");
}
if (cur_freq_file) {
rewind(cur_freq_file);
Expand Down Expand Up @@ -139,8 +139,8 @@ cpu_temperature(void)
|| (temperature_file = fopen("/proc/acpi/thermal_zone/THM/temperature", "r"))
|| (temperature_file = fopen("/proc/acpi/thermal_zone/THM0/temperature", "r"))
|| (temperature_file = fopen("/proc/acpi/thermal_zone/THRM/temperature", "r")))
{
if (1 != fscanf(temperature_file, format, &T))
{
if (1 != fscanf(temperature_file, format, &T))
format = "%d"; // Fallback to simple int
} else {
unavailable = TRUE;
Expand All @@ -152,14 +152,15 @@ cpu_temperature(void)
fflush(temperature_file);
if (1==fscanf(temperature_file, format, &T)) {
if (T>1000) T=(T+500)/1000;
return T;
return T;
}

unavailable = TRUE;
return 0;
}

typedef struct { int Total, Free, Available; } MemInfo;
// Memory info in megabytes
typedef struct { int Total_MB, Free_MB, Available_MB; } MemInfo;
MemInfo meminfo = {0};
MemInfo
mem_info(void)
Expand All @@ -170,12 +171,16 @@ mem_info(void)

static FILE* proc_meminfo = NULL;
if (proc_meminfo || (proc_meminfo = fopen("/proc/meminfo", "r")))
{
if (2==fscanf(proc_meminfo, "MemTotal: %d kB\nMemFree: %d kB\n"
, &meminfo.Total, &meminfo.Free))
{
int total, free;
if (2==fscanf(proc_meminfo, "MemTotal: %d kB\nMemFree: %d kB\n", &total, &free))
{
if (1!=fscanf(proc_meminfo, "MemAvailable: %d kB\n", &meminfo.Available))
meminfo.Available = meminfo.Free; // Fallback on older kernels
meminfo.Total_MB = total >> 10;
meminfo.Free_MB = free >> 10;
if (1==fscanf(proc_meminfo, "MemAvailable: %d kB\n", &free))
meminfo.Available_MB = free >> 10;
else
meminfo.Available_MB = meminfo.Free_MB; // Fallback on older kernels
rewind(proc_meminfo);
fflush(proc_meminfo);
return meminfo;
Expand Down
Loading

0 comments on commit 806f364

Please sign in to comment.