Beispiel #1
0
/* battery_on_timeout */
static gboolean _battery_on_timeout(gpointer data)
{
	const gdouble error = 0.0 / 0.0;
	Battery * battery = data;
	PanelAppletHelper * helper = battery->helper;
	gdouble level;
	gboolean charging;
	int timeout;

	if(_battery_get(battery, &level, &charging) == FALSE)
	{
		helper->error(NULL, error_get(NULL), 1);
		timeout = 0;
	}
	else if(level == error || level < 0.0)
	{
		helper->error(NULL, error_get(NULL), 1);
		timeout = 30000;
	}
	else
		timeout = 5000;
	_battery_set(battery, level, charging);
	battery->timeout = (timeout > 0)
		? g_timeout_add(timeout, _battery_on_timeout, battery) : 0;
	return FALSE;
}
Beispiel #2
0
/* clock_on_timeout */
static gboolean _clock_on_timeout(gpointer data)
{
	Clock * clock = data;
	PanelAppletHelper * helper = clock->helper;
	struct timeval tv;
	time_t t;
	struct tm tm;
	char buf[32];

	if(gettimeofday(&tv, NULL) != 0)
	{
		error_set("%s: %s: %s", applet.name, "gettimeofday",
				strerror(errno));
		helper->error(NULL, error_get(NULL), 1);
		return TRUE;
	}
	t = tv.tv_sec;
	localtime_r(&t, &tm);
	strftime(buf, sizeof(buf), clock->format, &tm);
	gtk_label_set_text(GTK_LABEL(clock->label), buf);
#ifndef EMBEDDED
	if(clock->iconsize != GTK_ICON_SIZE_LARGE_TOOLBAR)
	{
		strftime(buf, sizeof(buf), _("%H:%M:%S\n%d/%m/%Y"), &tm);
		gtk_widget_set_tooltip_text(clock->label, buf);
	}
#endif
	return TRUE;
}
Beispiel #3
0
/* cpufreq_on_timeout */
static gboolean _cpufreq_on_timeout(gpointer data)
{
	Cpufreq * cpufreq = data;
	PanelAppletHelper * helper = cpufreq->helper;
	uint64_t freq;
	size_t freqsize = sizeof(freq);
	char buf[256];

	if(sysctlbyname(cpufreq->name, &freq, &freqsize, NULL, 0) < 0)
	{
		error_set("%s: %s: %s", applet.name, cpufreq->name,
				strerror(errno));
		helper->error(NULL, error_get(NULL), 1);
		return TRUE;
	}
	snprintf(buf, sizeof(buf), "%4u", (unsigned int)freq);
	gtk_label_set_text(GTK_LABEL(cpufreq->label), buf);
# if GTK_CHECK_VERSION(2, 12, 0)
	snprintf(buf, sizeof(buf), "%s%u %s", _("CPU frequency: "),
			(unsigned int)freq, _("MHz"));
	gtk_widget_set_tooltip_text(cpufreq->hbox, buf);
# endif
	return TRUE;
}