diff options
-rw-r--r-- | INSTALLATION.md | 21 | ||||
-rw-r--r-- | Makefile | 26 | ||||
-rw-r--r-- | README.md | 24 | ||||
-rw-r--r-- | TODO.md | 5 | ||||
-rw-r--r-- | bat_tray/bat_tray.h | 9 | ||||
-rw-r--r-- | bool.h | 14 | ||||
-rw-r--r-- | common.c | 18 | ||||
-rw-r--r-- | common.h | 14 | ||||
-rw-r--r-- | config_file.h | 8 | ||||
-rw-r--r-- | data/trayfreq.config | 4 | ||||
-rw-r--r-- | defaults.h | 4 | ||||
-rw-r--r-- | freq_tray/getcore.h | 4 | ||||
-rw-r--r-- | freq_tray/getfreq.c | 1 | ||||
-rw-r--r-- | freq_tray/getfreq.h | 14 | ||||
-rw-r--r-- | freq_tray/getgov.h | 10 | ||||
-rw-r--r-- | tray.c | 81 | ||||
-rw-r--r-- | tray.h | 27 | ||||
-rw-r--r-- | trayfreq.c | 7 | ||||
-rw-r--r-- | trayfreq_set/trayfreq_set.c | 3 | ||||
-rw-r--r-- | trayfreq_set/trayfreq_set_interface.h | 4 | ||||
-rw-r--r-- | widget_manager.h | 2 |
21 files changed, 145 insertions, 155 deletions
diff --git a/INSTALLATION.md b/INSTALLATION.md deleted file mode 100644 index 175d39e..0000000 --- a/INSTALLATION.md +++ /dev/null @@ -1,21 +0,0 @@ -Installation -============ -The basic installation's standard: - -make install - ----------------------------------- - -Autostarting ------------- -`make install` will copy a .desktop file over to /etc/xdg/autostart, meaning that all xdg-compliant window managers should start it automatically when you log in. -As far as I am aware, they start trayfreq as root, thus it is fully able to change the governor. - -Personally, I use a non-xdg-compliant WM (dwm) so trayfreq needs to be run with sudo in my xinitrc. -To avoid having to enter my password each time the xinitrc is run, I added this rule to my `/etc/sudoers`: - - # ... (/etc/sudoers - david ALL = NOPASSWD: /usr/bin/trayfreq - # ... - -Simple. @@ -4,19 +4,19 @@ MAKE = make CC = gcc INSTALL_PATH=/ -GLIB_CFLAGS = -I/usr/include/glib-2.0 \ - -I/usr/lib/glib-2.0/include -GLIB_LIBS = -lglib-2.0 -GTK_CFLAGS = -I/usr/include/gtk-2.0 \ - -I/usr/lib/gtk-2.0/include \ - -I/usr/include/pango-1.0 \ - -I/usr/include/cairo \ - -I/usr/include/gdk-pixbuf-2.0 \ - -I/usr/include/atk-1.0 +GLIB_CFLAGS = -I/usr/include/glib-2.0 \ + -I/usr/lib/glib-2.0/include +GLIB_LIBS = -lglib-2.0 -GTK_LIBS = -lgtk-3 \ - -lgobject-2.0 +GTK_CFLAGS = -I/usr/include/gtk-2.0 \ + -I/usr/lib/gtk-2.0/include \ + -I/usr/include/pango-1.0 \ + -I/usr/include/cairo \ + -I/usr/include/gdk-pixbuf-2.0 \ + -I/usr/include/atk-1.0 +GTK_LIBS = -lgtk-3 \ + -lgobject-2.0 trayfreq_CFLAGS = $(GTK_CFLAGS) $(GLIB_CFLAGS) -Wall -D_=gettext @@ -33,8 +33,8 @@ trayfreq_SOURCES = freq_tray/getcore.c \ bat_tray/bat_tray.c \ common.c -trayfreq_set_CFLAGS = $(GTK_CFLAGS) $(GLIB_CFLAGS) -Wall -D_=gettext -trayfreq_set_LDFLAGS = $(GTK_LIBS) $(GLIB_LIBS) -lm +trayfreq_set_CFLAGS = $(GLIB_CFLAGS) -Wall -D_=gettext +trayfreq_set_LDFLAGS = $(GLIB_LIBS) -lm trayfreq_set_SOURCES = trayfreq_set/trayfreq_set.c \ freq_tray/getfreq.c \ freq_tray/getcore.c @@ -2,3 +2,27 @@ What? ===== This is a fork of trayfreq which is intended to work on modern Archlinux systems (it'll probably work on other systems too). + + + +Installation +============ +The basic installation's standard: + +make install + +---------------------------------- + +Autostarting +------------ +`make install` will copy a .desktop file over to /etc/xdg/autostart, meaning that all xdg-compliant window managers should start it automatically when you log in. +As far as I am aware, they start trayfreq as root, thus it is fully able to change the governor. + +Personally, I use a non-xdg-compliant WM (dwm) so trayfreq needs to be run with sudo in my xinitrc. +To avoid having to enter my password each time the xinitrc is run, I added this rule to my `/etc/sudoers`: + + # ... (/etc/sudoers + david ALL = NOPASSWD: /usr/bin/trayfreq + # ... + +Simple. diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 0085300..0000000 --- a/TODO.md +++ /dev/null @@ -1,5 +0,0 @@ -To do -===== - -* Receive feedback on French translation -* Clean up `trayfreq-set`'s `main()` diff --git a/bat_tray/bat_tray.h b/bat_tray/bat_tray.h index c20a833..8992b32 100644 --- a/bat_tray/bat_tray.h +++ b/bat_tray/bat_tray.h @@ -17,7 +17,7 @@ ************************************************************************/ #ifndef BAT_TRAY_H -#define BAT_TRAY_H 1 +#define BAT_TRAY_H #include <glib.h> @@ -33,8 +33,7 @@ void bat_tray_init(); void bat_tray_show(); void bat_tray_hide(); +int get_battery_state(); +int get_bat_num(); -int get_battery_state(); -int get_bat_num(); - -#endif /* ifndef BAT_TRAY_H */
\ No newline at end of file +#endif /* ifndef BAT_TRAY_H */ @@ -0,0 +1,14 @@ +#ifndef BOOL_H +#define BOOL_H + + #include <stdbool.h> + + #ifndef TRUE + #define TRUE true + #endif + + #ifndef FALSE + #define FALSE false + #endif + +#endif @@ -18,16 +18,8 @@ #include "common.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> - -#define TRUE true -#define FALSE false - /*********************************************************************** - * Gets integer value from file + * Gets integer value from first line in file **********************************************************************/ int get_int_value_from_file(const char* filename) { @@ -47,7 +39,7 @@ int get_int_value_from_file(const char* filename) /*********************************************************************** - * Return true/false if a file has specified line or not + * Return true/false if a file has specified line of text **********************************************************************/ bool file_has_line(const char *filename, const char *line) { @@ -71,14 +63,14 @@ bool file_has_line(const char *filename, const char *line) /*********************************************************************** - * Fetches first number from a string + * Fetches first number (ie the 35 of "35 123") from a + * string **********************************************************************/ int get_int(const char* string) { - char numbers[] = "1234567890"; char* first_num; - first_num = strpbrk(string, numbers); + first_num = strpbrk(string, "0123456789"); if(first_num) return atoi(first_num); @@ -17,12 +17,16 @@ ************************************************************************/ #ifndef COMMON_H -#define COMMON_H 1 +#define COMMON_H -#include <stdbool.h> +#include "bool.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> -int get_int_value_from_file(const char* filename); + +int get_int_value_from_file(const char* filename); +int get_int(const char* string); bool file_has_line(const char *filename, const char *line); -int get_int(const char* string); -#endif
\ No newline at end of file +#endif diff --git a/config_file.h b/config_file.h index cb491d4..d8e150b 100644 --- a/config_file.h +++ b/config_file.h @@ -17,7 +17,7 @@ ************************************************************************/ #ifndef CONFIG_FILE_H -#define CONFIG_FILE_H 1 +#define CONFIG_FILE_H #include <glib.h> @@ -28,7 +28,7 @@ struct config_file }; gboolean config_open(struct config_file* config_file); -void config_close(struct config_file* config_file); -gchar* config_get_key(struct config_file* config_file, const gchar* group_name, const gchar* key_name); +void config_close(struct config_file* config_file); +gchar* config_get_key(struct config_file* config_file, const gchar* group_name, const gchar* key_name); -#endif /* ifndef CONFIG_FILE_H */
\ No newline at end of file +#endif /* ifndef CONFIG_FILE_H */ diff --git a/data/trayfreq.config b/data/trayfreq.config index 2c5e6db..8783104 100644 --- a/data/trayfreq.config +++ b/data/trayfreq.config @@ -3,9 +3,7 @@ #governor=powersave #[ac] #governor=ondemand -#[events] -#activate=/usr/bin/xterm #[governor] #default=ondemand #[frequency] -#default=800000
\ No newline at end of file +#default=800000 @@ -17,7 +17,7 @@ ************************************************************************/ #ifndef DEFAULTS_H -#define DEFAULTS_H 1 +#define DEFAULTS_H #include <glib.h> @@ -27,4 +27,4 @@ char* _DEFAULT_PROG; char* _DEFAULT_BAT_GOV; char* _DEFAULT_AC_GOV; -#endif /* ifndef DEFAULTS_H */
\ No newline at end of file +#endif /* ifndef DEFAULTS_H */ diff --git a/freq_tray/getcore.h b/freq_tray/getcore.h index 541d789..fc1fc8d 100644 --- a/freq_tray/getcore.h +++ b/freq_tray/getcore.h @@ -17,9 +17,9 @@ ************************************************************************/ #ifndef GETCORE_H -#define GETCORE_H 1 +#define GETCORE_H void gc_init(); -int gc_number(); +int gc_number(); #endif diff --git a/freq_tray/getfreq.c b/freq_tray/getfreq.c index 7ac2181..02970b4 100644 --- a/freq_tray/getfreq.c +++ b/freq_tray/getfreq.c @@ -16,7 +16,6 @@ * <http://www.gnu.org/licenses/>. * ************************************************************************/ -#include "string.h" #include "getfreq.h" #include "getcore.h" #include "math.h" diff --git a/freq_tray/getfreq.h b/freq_tray/getfreq.h index a1cbd92..8df9eca 100644 --- a/freq_tray/getfreq.h +++ b/freq_tray/getfreq.h @@ -17,15 +17,15 @@ ************************************************************************/ #ifndef GETFREQ_H -#define GETFREQ_H 1 +#define GETFREQ_H -void gf_init(); -int gf_current(int core); -int gf_available(int core, char* out, int size); -void gf_get_frequency_label(int freq, char* out); +void gf_init(); +int gf_current(int core); +int gf_available(int core, char* out, int size); +void gf_get_frequency_label(int freq, char* out); char* gf_freqa(int core, int index); -int gf_freqi(int core, int index); -int gf_number(); +int gf_freqi(int core, int index); +int gf_number(); #endif diff --git a/freq_tray/getgov.h b/freq_tray/getgov.h index b4fdc29..fca341d 100644 --- a/freq_tray/getgov.h +++ b/freq_tray/getgov.h @@ -17,12 +17,12 @@ ************************************************************************/ #ifndef GETGOV_H -#define GETGOV_H 1 +#define GETGOV_H -void gg_init(); -int gg_current(int core, char* out, int size); -int gg_available(int core, char* out, int size); +void gg_init(); +int gg_current(int core, char* out, int size); +int gg_available(int core, char* out, int size); char* gg_gov(int core, int index); -int gg_number(); +int gg_number(); #endif @@ -17,28 +17,11 @@ ************************************************************************/ #include "tray.h" -#include "widget_manager.h" -#include "freq_tray/getfreq.h" -#include "freq_tray/getcore.h" -#include "freq_tray/getgov.h" -#include "trayfreq_set/trayfreq_set_interface.h" -#include "bat_tray/bat_tray.h" -#include "defaults.h" - -#include <gtk/gtk.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <libintl.h> -GtkStatusIcon* tray; #define TOOLTIP_TEXT_SIZE 500 -gchar tooltip_text[TOOLTIP_TEXT_SIZE]; - - -/* 0 = nothing, 1 = was charging, 2 = was discharging */ -//int state = 0; +GtkStatusIcon* tray; +gchar tooltip_text[TOOLTIP_TEXT_SIZE]; GtkWidget* menu; GSList* menu_items; @@ -105,8 +88,8 @@ static void tray_generate_menu() int i = 0; gchar current_governor[20]; - memset(current_governor, '\0', 20); - gg_current(0, current_governor, 20); + memset(current_governor, '\0', sizeof(current_governor) ); + gg_current(0, current_governor, sizeof(current_governor) ); gint current_frequency = gf_current(0); @@ -152,39 +135,42 @@ static void tray_generate_menu() static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean keyboard_mode,GtkTooltip* tooltip,gpointer data) { - gchar msg[500]; - gchar current_governer[20]; + gchar msg[TOOLTIP_TEXT_SIZE]; + gchar current_governor[20]; gchar label[20]; int i = 0; - memset(msg, 0, 500); - memset(current_governer, 0, 20); + memset(msg, '\0', sizeof(msg)); + memset(current_governor, '\0', sizeof(current_governor) ); - // Change governor based on battery state battery is discharging - if ( get_battery_state() == STATE_DISCHARGING ) - { - if(_DEFAULT_BAT_GOV) - { - for(i = 0; i < gc_number(); ++i) - si_gov(_DEFAULT_BAT_GOV, i); - } - } - /* battery is now charging (on ac) */ - else if ( get_battery_state() == STATE_CHARGING ) + + switch ( get_battery_state() ) { - if(_DEFAULT_AC_GOV) - { - for(i = 0; i < gc_number(); ++i) - si_gov(_DEFAULT_AC_GOV, i); - } + case STATE_DISCHARGING: + if(_DEFAULT_BAT_GOV) + { + for(i = 0; i < gc_number(); ++i) + si_gov(_DEFAULT_BAT_GOV, i); + } + break; + + case STATE_CHARGING: + case STATE_FULL: + if(_DEFAULT_AC_GOV) + { + for(i = 0; i < gc_number(); ++i) + si_gov(_DEFAULT_AC_GOV, i); + } + + break; } - gg_current(0, current_governer, 20); - sprintf(msg+strlen(msg), _("Governor: %s\n"), current_governer); + gg_current(0, current_governor, sizeof(current_governor) ); + sprintf(msg+strlen(msg), _("Governor: %s\n"), current_governor); for(i = 0; i < gc_number(); ++i) { - memset(label, 0, 20); + memset(label, '\0', sizeof(label)); gf_get_frequency_label(gf_current(i), label); sprintf(msg+strlen(msg), _("CPU%i: %s%s"), i, label, i == gc_number()-1 ? "" : "\n"); } @@ -201,12 +187,6 @@ static void popup_menu(GtkStatusIcon* statuc_icon,guint button,guint activate_ti gtk_menu_popup(GTK_MENU(menu),NULL,NULL,gtk_status_icon_position_menu,tray,button,activate_time); } -static void activate(GtkStatusIcon* statuc_icon,gpointer data) -{ - if(_DEFAULT_PROG) - g_spawn_command_line_async(_DEFAULT_PROG, NULL); -} - static gboolean update_icon(gpointer user_data) { tray_update_icon_percent(); @@ -241,7 +221,6 @@ void tray_init() gtk_status_icon_set_has_tooltip (tray, TRUE); g_signal_connect(G_OBJECT(tray), "query-tooltip", GTK_SIGNAL_FUNC(update_tooltip), NULL); g_signal_connect(G_OBJECT(tray), "popup-menu", GTK_SIGNAL_FUNC(popup_menu), NULL); - g_signal_connect(G_OBJECT(tray), "activate", GTK_SIGNAL_FUNC(activate), NULL); g_timeout_add(1000, update_icon, NULL); tray_init_menu(); } @@ -17,15 +17,30 @@ ************************************************************************/ #ifndef TRAY_H -#define TRAY_H 1 +#define TRAY_H #include <glib.h> -void tray_init(); -void tray_set_tooltip(const gchar* msg); -void tray_update_icon_percent(); -void tray_show(); -void tray_hide(); +#include "widget_manager.h" +#include "freq_tray/getfreq.h" +#include "freq_tray/getcore.h" +#include "freq_tray/getgov.h" +#include "trayfreq_set/trayfreq_set_interface.h" +#include "bat_tray/bat_tray.h" +#include "defaults.h" + +#include <gtk/gtk.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <libintl.h> + + +void tray_init(); +void tray_set_tooltip(const gchar* msg); +void tray_update_icon_percent(); +void tray_show(); +void tray_hide(); gboolean tray_visible(); gboolean tray_embedded(); @@ -16,8 +16,6 @@ * <http://www.gnu.org/licenses/>. * ************************************************************************/ -#include "strings.h" - #include "widget_manager.h" #include "tray.h" #include "bat_tray/bat_tray.h" @@ -68,16 +66,12 @@ void config_init() return; } - gchar * def_prog = config_get_key(&config, "events", "activate"); 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_prog) - _DEFAULT_PROG = def_prog; - if(def_gov) _DEFAULT_GOV = def_gov; @@ -112,7 +106,6 @@ int main(int argc, char** argv) g_error(_("GTK Error: gtk_init_check returned FALSE.\nBailing.") ); return 1; } - config_init(); gc_init(); gg_init(); diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set/trayfreq_set.c index a9de8c1..737b7c9 100644 --- a/trayfreq_set/trayfreq_set.c +++ b/trayfreq_set/trayfreq_set.c @@ -22,7 +22,6 @@ #include <libintl.h> #include <locale.h> -#include "../strings.h" #include "../freq_tray/getfreq.h" #include "../freq_tray/getcore.h" @@ -31,7 +30,7 @@ char file_path[100]; void prepare_path(const char* file, const char* core) { - // Sanatise core to make sure there's not monkey business going on -- it's only an integer + // Sanatise core to make sure there's not monkey business going on int core_i = atoi(core); sprintf(file_path, "/sys/devices/system/cpu/cpu%d/cpufreq/%s", core_i, file); diff --git a/trayfreq_set/trayfreq_set_interface.h b/trayfreq_set/trayfreq_set_interface.h index 3f1cdbc..bdbf652 100644 --- a/trayfreq_set/trayfreq_set_interface.h +++ b/trayfreq_set/trayfreq_set_interface.h @@ -17,9 +17,9 @@ ************************************************************************/ #ifndef TRAYFREQ_SET_INTERFACE_H -#define TRAYFREQ_SET_INTERFACE_H 1 +#define TRAYFREQ_SET_INTERFACE_H void si_gov(char* gov, int core); void si_freq(int freq, int core); -#endif
\ No newline at end of file +#endif diff --git a/widget_manager.h b/widget_manager.h index 264c79d..d6c2d10 100644 --- a/widget_manager.h +++ b/widget_manager.h @@ -17,7 +17,7 @@ ************************************************************************/ #ifndef WIDGET_MANAGER_H -#define WIDGET_MANAGER_H 1 +#define WIDGET_MANAGER_H #include <gtk/gtk.h> #include <glib.h> |