aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--config_file.c6
-rw-r--r--data/trayfreq.conf36
-rw-r--r--data/trayfreq.config9
-rw-r--r--defaults.c11
-rw-r--r--defaults.h3
-rw-r--r--freq_tray/getcore.c2
-rw-r--r--lc/fr.po7
-rw-r--r--trayfreq.c46
-rw-r--r--trayfreq_set/trayfreq_set_interface.c15
-rw-r--r--trayfreq_set/trayfreq_set_interface.h2
11 files changed, 86 insertions, 53 deletions
diff --git a/Makefile b/Makefile
index 5da4886..37e89c4 100644
--- a/Makefile
+++ b/Makefile
@@ -83,7 +83,7 @@ install:
mkdir -p $(INSTALL_PATH)/usr/share/locale/fr/LC_MESSAGES/
cp lc/fr.mo $(INSTALL_PATH)/usr/share/locale/fr/LC_MESSAGES/trayfreq.mo
- install -Dm 644 data/trayfreq.config $(INSTALL_PATH)/usr/share/trayfreq/trayfreq.config
+ install -Dm 644 data/trayfreq.conf $(INSTALL_PATH)/usr/share/trayfreq/trayfreq.conf
install -Dm 644 data/trayfreq.desktop $(INSTALL_PATH)/etc/xdg/autostart/trayfreq.desktop
install -Dm 755 trayfreq $(INSTALL_PATH)/usr/bin/trayfreq
install -Dm 755 trayfreq-set $(INSTALL_PATH)/usr/bin/trayfreq-set
diff --git a/config_file.c b/config_file.c
index 602eb92..a62f094 100644
--- a/config_file.c
+++ b/config_file.c
@@ -28,11 +28,13 @@ gboolean config_open(struct config_file* config_file)
debug("Creating new config_file->key_file\n");
config_file->key_file = g_key_file_new();
-
- return g_key_file_load_from_file( config_file->key_file,
+ gboolean success = g_key_file_load_from_file(
+ config_file->key_file,
config_file->file_name,
G_KEY_FILE_NONE,
NULL);
+ debug("Returning %s\n",success? "TRUE" : "FALSE");
+ return success;
}
void config_close(struct config_file* config_file)
diff --git a/data/trayfreq.conf b/data/trayfreq.conf
new file mode 100644
index 0000000..59dc4d8
--- /dev/null
+++ b/data/trayfreq.conf
@@ -0,0 +1,36 @@
+# Begin /usr/share/trayfreq/trayfreq.conf
+#
+# Sample config file for trayfreq-archlinux
+#
+
+[battery]
+## Uncomment to hide battery icon -- useful for desktop PCs
+# show=0
+
+## Governor to use for all cores when on battery power
+# governor=powersave
+
+[ac]
+## Governor to use for all core while on AC power
+## Often set to a performance or non-power-saving governor
+# governor=ondemand
+
+[governor]
+## Governor to set all cores to when trayfreq starts
+# default=ondemand
+
+
+## The frequency to set the CPU to when trayfreq starts
+[frequency]
+# default=800000
+
+
+[extra]
+## Uncomment to make trayfreq run trayfreq-set through sudo.
+## Useful if your WM doesn't run trayfreq as root, but you'll have to give the user
+## trayfreq is run as passwordless sudo access to `trayfreq-set`
+# sudo=1
+
+
+#
+# End /usr/share/trayfreq/trayfreq.conf
diff --git a/data/trayfreq.config b/data/trayfreq.config
deleted file mode 100644
index 8783104..0000000
--- a/data/trayfreq.config
+++ /dev/null
@@ -1,9 +0,0 @@
-#[battery]
-#show=1
-#governor=powersave
-#[ac]
-#governor=ondemand
-#[governor]
-#default=ondemand
-#[frequency]
-#default=800000
diff --git a/defaults.c b/defaults.c
index dc54dd4..6b605fc 100644
--- a/defaults.c
+++ b/defaults.c
@@ -18,8 +18,9 @@
#include "defaults.h"
-char* _DEFAULT_GOV = NULL;
-char* _DEFAULT_FREQ = NULL;
-char* _DEFAULT_PROG = NULL;
-char* _DEFAULT_BAT_GOV = NULL;
-char* _DEFAULT_AC_GOV = NULL; \ No newline at end of file
+char* _DEFAULT_GOV;
+char* _DEFAULT_FREQ;
+char* _DEFAULT_PROG;
+char* _DEFAULT_BAT_GOV;
+char* _DEFAULT_AC_GOV;
+bool _DEFAULT_USE_SUDO = FALSE;
diff --git a/defaults.h b/defaults.h
index b92859c..f1d4202 100644
--- a/defaults.h
+++ b/defaults.h
@@ -19,12 +19,13 @@
#ifndef DEFAULTS_H
#define DEFAULTS_H
-#include <glib.h>
+#include "bool.h"
char* _DEFAULT_GOV;
char* _DEFAULT_FREQ;
char* _DEFAULT_PROG;
char* _DEFAULT_BAT_GOV;
char* _DEFAULT_AC_GOV;
+bool _DEFAULT_USE_SUDO;
#endif /* ifndef DEFAULTS_H */
diff --git a/freq_tray/getcore.c b/freq_tray/getcore.c
index 44b3940..ad4878f 100644
--- a/freq_tray/getcore.c
+++ b/freq_tray/getcore.c
@@ -32,7 +32,7 @@ static gboolean core_exists(unsigned int core)
sprintf(corestr, "%d", core);
sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr);
- debug("Checking if core %d exists by opening '%s'",core,path);
+ debug("Checking if core %d exists by opening '%s'\n",core,path);
return (gboolean)(fd = fopen(path, "r"));
}
diff --git a/lc/fr.po b/lc/fr.po
index 9e237ca..fdcecc5 100644
--- a/lc/fr.po
+++ b/lc/fr.po
@@ -1,9 +1,8 @@
# French translation of strings for trayfreq-archlinux.
# Copyright (C) David Phillips
# This file is distributed under the same license as the trayfreq-archlinux package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+# David Phillips <dbphillipsnz@gmail.com>, 2014.
#
-#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: trayfreq-archlinux 0.5\n"
@@ -27,11 +26,11 @@ msgstr "Profil: %s\n"
msgid "CPU%i: %s%s"
msgstr "CPU%i: %s%s"
-#: trayfreq.c:70
+#: trayfreq.c:69
msgid "Failed to open config files!\n"
msgstr "Pouvais pas ouvrier les fichiers config !\n"
-#: trayfreq.c:113
+#: trayfreq.c:105
msgid ""
"GTK Error: gtk_init_check returned FALSE.\n"
"Bailing."
diff --git a/trayfreq.c b/trayfreq.c
index e3b925e..4c23982 100644
--- a/trayfreq.c
+++ b/trayfreq.c
@@ -42,7 +42,7 @@ void config_init()
gboolean home_config_exists;
config.key_file = NULL;
- config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.config", NULL);
+ config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.conf", NULL);
// Check if ~/.trayfreq.config exists
@@ -60,42 +60,34 @@ void config_init()
}
if(!home_config_exists)
- config.file_name = g_strconcat("/usr/share/trayfreq/trayfreq.config", NULL);
+ config.file_name = g_strconcat("/usr/share/trayfreq/trayfreq.conf", NULL);
gboolean success = config_open(&config);
-
if(!success)
{
debug("Couldn't open '%s' for reading\n",config.file_name);
g_warning(_("Failed to open config files!\n"));
return;
}
-
- gchar * def_gov = config_get_key(&config, "governor", "default");
- gchar * def_freq = config_get_key(&config, "frequency", "default");
- gchar * show_bat = config_get_key(&config, "battery", "show");
- gchar * bat_gov = config_get_key (&config, "battery", "governor");
- gchar * ac_gov = config_get_key (&config, "ac", "governor");
-
- if(def_gov)
- _DEFAULT_GOV = def_gov;
-
- if(def_freq)
- _DEFAULT_FREQ = def_freq;
-
- if (bat_gov)
- _DEFAULT_BAT_GOV = bat_gov;
-
- if (ac_gov)
- _DEFAULT_AC_GOV = ac_gov;
-
- if(show_bat)
+ _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");
+ _DEFAULT_AC_GOV = config_get_key(&config, "ac", "governor");
+
+ char* temp = config_get_key(&config, "battery", "show");
+ if (temp)
+ SHOW_BATTERY = ( temp[0] == '1' );
+
+ temp = config_get_key(&config, "extra", "sudo");
+ if (temp)
{
- if(g_strcmp0(show_bat, "1") == 0)
- SHOW_BATTERY = TRUE;
- else
- SHOW_BATTERY = FALSE;
+ _DEFAULT_USE_SUDO = ( temp[0] == '1' );
+ debug("woo\n");
}
+
+
+ debug("%s sudo\n",_DEFAULT_USE_SUDO? "Using" : "Not using");
+
g_free(config.file_name);
config_close(&config);
}
diff --git a/trayfreq_set/trayfreq_set_interface.c b/trayfreq_set/trayfreq_set_interface.c
index 490d50c..3e26112 100644
--- a/trayfreq_set/trayfreq_set_interface.c
+++ b/trayfreq_set/trayfreq_set_interface.c
@@ -18,20 +18,29 @@
#include "trayfreq_set_interface.h"
-#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
void si_gov(char* gov, int core)
{
char cmd[256];
- sprintf(cmd, "/usr/bin/trayfreq-set -g %s -c %i",gov,core);
+ if (_DEFAULT_USE_SUDO)
+ {
+ sprintf(cmd, "sudo trayfreq-set -g %s -c %i",gov,core);
+ } else {
+ sprintf(cmd, "trayfreq-set -g %s -c %i",gov,core);
+ }
system(cmd);
}
void si_freq(int freq, int core)
{
char cmd[256];
- sprintf(cmd, "/usr/bin/trayfreq-set -f %i -c %i",freq,core);
+ if (_DEFAULT_USE_SUDO)
+ {
+ sprintf(cmd, "sudo trayfreq-set -f %i -c %i",freq,core);
+ } else {
+ sprintf(cmd, "trayfreq-set -f %i -c %i",freq,core);
+ }
system(cmd);
}
diff --git a/trayfreq_set/trayfreq_set_interface.h b/trayfreq_set/trayfreq_set_interface.h
index bdbf652..c5681e4 100644
--- a/trayfreq_set/trayfreq_set_interface.h
+++ b/trayfreq_set/trayfreq_set_interface.h
@@ -19,6 +19,8 @@
#ifndef TRAYFREQ_SET_INTERFACE_H
#define TRAYFREQ_SET_INTERFACE_H
+#include "../defaults.h"
+
void si_gov(char* gov, int core);
void si_freq(int freq, int core);