Tue Oct 26 17:44:38 PDT 1999
(KainX) E-Sys, an uptime epplet that actually *works*. :-) SVN revision: 992
This commit is contained in:
parent
cc45df368c
commit
187b738248
|
@ -153,3 +153,10 @@ Epplet_query_config_def() instead and passing the default to that function.
|
|||
|
||||
I also added the ability to right-justify label text by specifying a negative
|
||||
x coordinate. See E-Time for a sample.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Tue Oct 26 17:44:38 PDT 1999
|
||||
(KainX)
|
||||
|
||||
E-Sys, an uptime epplet that actually *works*. :-)
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
#include "epplet.h"
|
||||
|
||||
#if 0
|
||||
# define D(x) do {printf("%10s | %7d: [debug] ", __FILE__, __LINE__); printf x; fflush(stdout);} while (0)
|
||||
#else
|
||||
# define D(x) ((void) 0)
|
||||
#endif
|
||||
#define BEGMATCH(a, b) (!strncasecmp((a), (b), (sizeof(b) - 1)))
|
||||
#define NONULL(x) ((x) ? (x) : (""))
|
||||
|
||||
Epplet_gadget close_button, label1, label2, label3, label4;
|
||||
int mem_val = 0, swap_val = 0;
|
||||
|
||||
static void timer_cb(void *data);
|
||||
static void close_cb(void *data);
|
||||
static void in_cb(void *data, Window w);
|
||||
static void out_cb(void *data, Window w);
|
||||
|
||||
static void
|
||||
timer_cb(void *data) {
|
||||
|
||||
FILE *fp;
|
||||
char buff[1024];
|
||||
unsigned long days, hours, mins, secs;
|
||||
double total_secs, delay;
|
||||
|
||||
if ((fp = fopen("/proc/uptime", "r")) == NULL) {
|
||||
D(("Failed to open /proc/uptime -- %s\n", strerror(errno)));
|
||||
return;
|
||||
}
|
||||
fgets(buff, sizeof(buff), fp);
|
||||
sscanf(buff, "%lf", &total_secs);
|
||||
secs = (unsigned long) total_secs;
|
||||
|
||||
days = secs / 86400;
|
||||
secs %= 86400;
|
||||
hours = secs / 3600;
|
||||
secs %= 3600;
|
||||
mins = secs / 60;
|
||||
secs %= 60;
|
||||
if (secs == 0) {
|
||||
secs = 60;
|
||||
}
|
||||
delay = (double) secs;
|
||||
|
||||
sprintf(buff, "%lu days", days);
|
||||
Epplet_change_label(label2, buff);
|
||||
sprintf(buff, "%lu hours", hours);
|
||||
Epplet_change_label(label3, buff);
|
||||
sprintf(buff, "%lu mins", mins);
|
||||
Epplet_change_label(label4, buff);
|
||||
|
||||
fclose(fp);
|
||||
Esync();
|
||||
Epplet_timer(timer_cb, NULL, delay, "TIMER");
|
||||
return;
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
close_cb(void *data) {
|
||||
|
||||
Epplet_unremember();
|
||||
Esync();
|
||||
exit(0);
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
in_cb(void *data, Window w) {
|
||||
|
||||
Epplet_gadget_show(close_button);
|
||||
return;
|
||||
data = NULL;
|
||||
w = (Window) 0;
|
||||
}
|
||||
|
||||
static void
|
||||
out_cb(void *data, Window w) {
|
||||
|
||||
Epplet_gadget_hide(close_button);
|
||||
return;
|
||||
data = NULL;
|
||||
w = (Window) 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
|
||||
int prio;
|
||||
|
||||
prio = getpriority(PRIO_PROCESS, getpid());
|
||||
setpriority(PRIO_PROCESS, getpid(), prio + 10);
|
||||
atexit(Epplet_cleanup);
|
||||
Epplet_Init("E-Sys", "0.1", "Enlightenment Uptime Epplet", 3, 3, argc, argv, 0);
|
||||
|
||||
close_button = Epplet_create_button(NULL, NULL, 34, 2, 0, 0, "CLOSE", 0, NULL, close_cb, NULL);
|
||||
label1 = Epplet_create_label(4, 4, "Uptime", 1);
|
||||
label2 = Epplet_create_label(4, 16, "", 1);
|
||||
label3 = Epplet_create_label(4, 26, "", 1);
|
||||
label4 = Epplet_create_label(4, 36, "", 1);
|
||||
Epplet_gadget_show(label1);
|
||||
Epplet_gadget_show(label2);
|
||||
Epplet_gadget_show(label3);
|
||||
Epplet_show();
|
||||
|
||||
Epplet_register_focus_in_handler(in_cb, NULL);
|
||||
Epplet_register_focus_out_handler(out_cb, NULL);
|
||||
timer_cb(NULL); /* Set everything up */
|
||||
Epplet_Loop();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -5,7 +5,7 @@ bindir = $(EBIN)
|
|||
bin_PROGRAMS = E-Load.epplet E-Clock.epplet E-Time.epplet E-Net.epplet \
|
||||
E-Cpu.epplet EppletTest.epplet E-Biff.epplet E-Power.epplet Emix.epplet \
|
||||
E-MemWatch.epplet E-Disk.epplet E-Areas.epplet EppletConfigTest.epplet \
|
||||
E-NetFlame.epplet
|
||||
E-NetFlame.epplet E-Sys.epplet
|
||||
|
||||
E_Load_epplet_SOURCES = E-Load.c
|
||||
E_Load_epplet_DEPENDENCIES = $(top_srcdir)/api/libepplet.la
|
||||
|
@ -59,6 +59,10 @@ E_Disk_epplet_SOURCES = E-Disk.c
|
|||
E_Disk_epplet_DEPENDENCIES = $(top_srcdir)/api/libepplet.la
|
||||
E_Disk_epplet_LDFLAGS = -rpath $(libdir):$(pkglibdir)
|
||||
|
||||
E_Sys_epplet_SOURCES = E-Sys.c
|
||||
E_Sys_epplet_DEPENDENCIES = $(top_srcdir)/api/libepplet.la
|
||||
E_Sys_epplet_LDFLAGS = -rpath $(libdir):$(pkglibdir)
|
||||
|
||||
Emix_epplet_SOURCES = Emix.c
|
||||
Emix_epplet_DEPENDENCIES = $(top_srcdir)/api/libepplet.la
|
||||
Emix_epplet_LDFLAGS = -rpath $(libdir):$(pkglibdir)
|
||||
|
|
Loading…
Reference in New Issue