aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--defaults.c11
-rw-r--r--defaults.h4
-rw-r--r--reload.c5
-rw-r--r--tray.c57
-rw-r--r--tray.h1
-rw-r--r--trayfreq.c4
-rw-r--r--trayfreq_set_interface.c4
7 files changed, 59 insertions, 27 deletions
diff --git a/defaults.c b/defaults.c
index 1e59095..926e1fd 100644
--- a/defaults.c
+++ b/defaults.c
@@ -25,3 +25,14 @@ char* _DEFAULT_BAT_GOV;
char* _DEFAULT_AC_GOV;
bool _DEFAULT_SHOW_BATTERY = TRUE;
bool _DEFAULT_USE_SUDO = FALSE;
+
+void defaults_init()
+{
+ _DEFAULT_GOV = NULL;
+ _DEFAULT_FREQ = NULL;
+ _DEFAULT_PROG = NULL;
+ _DEFAULT_BAT_GOV = NULL;
+ _DEFAULT_AC_GOV = NULL;
+ _DEFAULT_SHOW_BATTERY = TRUE;
+ _DEFAULT_USE_SUDO = FALSE;
+}
diff --git a/defaults.h b/defaults.h
index d1565d2..f79fc9a 100644
--- a/defaults.h
+++ b/defaults.h
@@ -20,6 +20,7 @@
#define DEFAULTS_H
#include "bool.h"
+#include <stdlib.h>
char* _DEFAULT_GOV;
char* _DEFAULT_FREQ;
@@ -29,4 +30,7 @@ char* _DEFAULT_AC_GOV;
bool _DEFAULT_SHOW_BATTERY;
bool _DEFAULT_USE_SUDO;
+
+void defaults_init();
+
#endif /* ifndef DEFAULTS_H */
diff --git a/reload.c b/reload.c
index 2026365..6b78dac 100644
--- a/reload.c
+++ b/reload.c
@@ -20,12 +20,15 @@
void reload_config()
{
+ debug("Reloading config\n");
config_init();
if (_DEFAULT_SHOW_BATTERY)
{
- bat_tray_hide();
+ //bat_tray_hide();
bat_tray_show();
} else {
bat_tray_hide();
}
+ debug("Re-init freq tray\n");
+ tray_set_defaults();
}
diff --git a/tray.c b/tray.c
index 05465c4..ecfc7ec 100644
--- a/tray.c
+++ b/tray.c
@@ -164,30 +164,6 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean
memset(msg, '\0', sizeof(msg));
memset(current_governor, '\0', sizeof(current_governor) );
-
- switch ( get_battery_state() )
- {
- case STATE_DISCHARGING:
- debug("Discharging\n");
- if(_DEFAULT_BAT_GOV)
- {
- for(i = 0; i < gc_number(); ++i)
- si_gov(_DEFAULT_BAT_GOV, i);
- }
- break;
-
- case STATE_CHARGING:
- case STATE_FULL:
- debug("Charging/Full\n");
- if(_DEFAULT_AC_GOV)
- {
- for(i = 0; i < gc_number(); ++i)
- si_gov(_DEFAULT_AC_GOV, i);
- }
-
- break;
- }
-
gg_current(0, current_governor, sizeof(current_governor) );
sprintf(msg+strlen(msg), _("Governor: %s\n"), current_governor);
@@ -215,12 +191,36 @@ static void popup_menu(GtkStatusIcon* statuc_icon,guint button,guint activate_ti
static gboolean update_icon(gpointer user_data)
{
+ int i;
+ switch ( get_battery_state() )
+ {
+ case STATE_DISCHARGING:
+ debug("Discharging\n");
+ if(_DEFAULT_BAT_GOV)
+ {
+ for(i = 0; i < gc_number(); ++i)
+ si_gov(_DEFAULT_BAT_GOV, i);
+ }
+ break;
+
+ case STATE_CHARGING:
+ case STATE_FULL:
+ debug("Charging/Full\n");
+ if(_DEFAULT_AC_GOV)
+ {
+ for(i = 0; i < gc_number(); ++i)
+ si_gov(_DEFAULT_AC_GOV, i);
+ }
+
+ break;
+ }
+
debug("Updating icon\n");
tray_update_icon_percent();
return TRUE;
}
-void tray_init()
+void tray_set_defaults()
{
// Set defaults
int i = 0;
@@ -240,6 +240,11 @@ void tray_init()
si_freq(atoi(_DEFAULT_FREQ), i);
}
+}
+
+void tray_init()
+{
+ tray_set_defaults();
tray = gtk_status_icon_new();
gchar* icon_file = g_strconcat("/usr/share/trayfreq/cpufreq-0.png", NULL);
@@ -268,7 +273,7 @@ void tray_update_icon_percent()
gulong max_frequency = gf_freqi(0, 0);
gint adjusted_percent = 0;
// If no governor, set percentage to 0. This if statement fixes an FPE a few lines down
- if (max_frequency == 0)
+ if (gg_number() == 0)
{
adjusted_percent = 0;
} else {
diff --git a/tray.h b/tray.h
index a9b0eed..b528ad6 100644
--- a/tray.h
+++ b/tray.h
@@ -36,6 +36,7 @@
#include <libintl.h>
+void tray_set_defaults();
void tray_init();
void tray_set_tooltip(const gchar* msg);
void tray_update_icon_percent();
diff --git a/trayfreq.c b/trayfreq.c
index 743bbaf..173f54f 100644
--- a/trayfreq.c
+++ b/trayfreq.c
@@ -52,6 +52,10 @@ void config_init()
g_warning(_("Failed to open config files!\n"));
return;
}
+
+ // Reset defaults to default values
+ defaults_init();
+
_DEFAULT_GOV = config_get_key(&config, "governor", "default");
_DEFAULT_FREQ = config_get_key(&config, "frequency", "default");
_DEFAULT_BAT_GOV = config_get_key(&config, "battery", "governor");
diff --git a/trayfreq_set_interface.c b/trayfreq_set_interface.c
index 3e26112..e64a88e 100644
--- a/trayfreq_set_interface.c
+++ b/trayfreq_set_interface.c
@@ -18,6 +18,8 @@
#include "trayfreq_set_interface.h"
+#include "debug.h"
+
#include <stdio.h>
#include <stdlib.h>
@@ -30,6 +32,7 @@ void si_gov(char* gov, int core)
} else {
sprintf(cmd, "trayfreq-set -g %s -c %i",gov,core);
}
+ debug("Running '%s'\n",cmd);
system(cmd);
}
@@ -42,5 +45,6 @@ void si_freq(int freq, int core)
} else {
sprintf(cmd, "trayfreq-set -f %i -c %i",freq,core);
}
+ debug("Running '%s'\n",cmd);
system(cmd);
}