From abbf6164e196115c488e26dc1bd3bf777a4e8039 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 30 Apr 2014 11:56:44 +1200 Subject: Inital jump to Gtk3 --- Makefile | 4 ++-- bat_tray/bat_tray.c | 2 +- tray.c | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2cda57a..21bb983 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,8 @@ GTK_CFLAGS = -I/usr/include/gtk-2.0 \ -I/usr/include/gdk-pixbuf-2.0 \ -I/usr/include/atk-1.0 -GTK_LIBS = -lgtk-x11-2.0 \ - -lgobject-2.0 +GTK_LIBS = -lgtk-3 \ + -lgobject-2.0 trayfreq_CFLAGS = $(GTK_CFLAGS) $(GLIB_CFLAGS) -Wall -D_=gettext diff --git a/bat_tray/bat_tray.c b/bat_tray/bat_tray.c index 181f8d5..ea7b3c7 100644 --- a/bat_tray/bat_tray.c +++ b/bat_tray/bat_tray.c @@ -135,7 +135,7 @@ void bat_tray_init() gtk_status_icon_set_from_file(tray, icon_file); gtk_status_icon_set_has_tooltip (tray, TRUE); g_signal_connect(G_OBJECT(tray), "query-tooltip", GTK_SIGNAL_FUNC(update_tooltip), NULL); - gtk_timeout_add(5000, update_icon, NULL); + g_timeout_add(5000, update_icon, NULL); } diff --git a/tray.c b/tray.c index ac9596d..eb6c65a 100644 --- a/tray.c +++ b/tray.c @@ -221,7 +221,8 @@ 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); - gtk_timeout_add(1000, update_icon, NULL); + g_signal_connect(G_OBJECT(tray), "activate", GTK_SIGNAL_FUNC(activate), NULL); + g_timeout_add(1000, update_icon, NULL); tray_init_menu(); } -- cgit v1.1 From 1b3a4514878ec8fb8c4156c38f608785a2bb0d64 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 30 Apr 2014 23:18:15 +1200 Subject: Changed cmd line args for the better, simplified and broke gov and freq setting --- trayfreq_set/trayfreq_set.c | 173 +++++++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 92 deletions(-) diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set/trayfreq_set.c index 737b7c9..4f28805 100644 --- a/trayfreq_set/trayfreq_set.c +++ b/trayfreq_set/trayfreq_set.c @@ -16,6 +16,9 @@ * . * ************************************************************************/ + +// : move a lot of this to a .h + #include #include #include @@ -25,132 +28,118 @@ #include "../freq_tray/getfreq.h" #include "../freq_tray/getcore.h" -char file_path[100]; - +#define FILE_PATH_STRING_SIZE 100 -void prepare_path(const char* file, const char* core) -{ - // Sanatise core to make sure there's not monkey business going on - int core_i = atoi(core); +#define ARG_CORE 0x1 +#define ARG_GOV 0x2 +#define ARG_FREQ 0x4 +typedef struct { + char present; + char *core; + char *governor; + char *frequency; +} argument_summary; - sprintf(file_path, "/sys/devices/system/cpu/cpu%d/cpufreq/%s", core_i, file); -} +// -void file_open_error() +char write_str_to_file(const char *file, const char *data, const char *core) { - printf( _("FAILED: Couldn't open %s for writing\n") , file_path); -} + FILE *fd; + char file_path[FILE_PATH_STRING_SIZE]; -void set_freq_max(const char* freq, const char* core) -{ + // Prepare file path + memset(file_path, '\0', sizeof(file_path)); + sprintf(file_path, "/sys/devices/system/cpu/cpu%d/cpufreq/%s", atoi(core), file ); - prepare_path("scaling_max_freq",core); - FILE* fd = fopen(file_path, "w"); - if (fd) + // Try to open file and write data to it + if ( !(fd = fopen(file_path, "w")) ) { - fprintf(fd, freq); + fprintf(fd, data); fclose(fd); - } else { - file_open_error(); + return 1; } + + // Fallthrough: File couldn't be opened for writing + printf( _("FAILED: Couldn't open %s for writing\n") , file_path); + return 0; } -void set_freq_min(char* freq, char* core) -{ - prepare_path("scaling_min_freq",core); - FILE* fd = fopen(file_path, "w"); - if (fd) - { - fprintf(fd, freq); - fclose(fd); - } else { - file_open_error(); - } -} +#define set_freq_max(freq,core) write_str_to_file("scaling_max_freq",freq,core) +#define set_freq_min(freq,core) write_str_to_file("scaling_min_freq",freq,core) +#define set_speed(freq,core) write_str_to_file("scaling_setspeed",freq,core) +#define set_gov(gov,core) write_str_to_file("scaling_governor",gov,core) +#define set_freq(freq,core) set_gov("userspace",core);set_speed(freq,core) -static void set_speed(char* freq, char* core) +void get_argument_summary(int argc, char **argv, argument_summary *argsum) { - prepare_path("scaling_setspeed",core); + int arg; - FILE* fd = fopen(file_path, "w"); - if (fd) + // Check for -{c,g,f} xyz + for ( arg = 1; arg < argc-1; arg+=2 ) { - fprintf(fd, freq); - fclose(fd); - } else { - file_open_error(); - } -} + // Can't have empty argument + if ( strlen(argv[arg+1]) != 0 ) + { + if ( strcmp(argv[arg], "-c") == 0 ) + { + // Found -c with an arg + argsum->present |= ARG_CORE; + argsum->core = (char*)(argv[arg+1]); + continue; + } -void set_gov(char* gov, char* core) -{ - prepare_path("scaling_governor",core); + if ( strcmp(argv[arg], "-f") == 0 ) + { + // Found -f with an arg + argsum->present |= ARG_FREQ; + argsum->frequency = (char*)(argv[arg+1]); + continue; + } - FILE* fd = fopen(file_path, "w"); - if (fd) - { - fprintf(fd, gov); - fclose(fd); - } else { - file_open_error(); + if ( strcmp(argv[arg], "-g") == 0 ) + { + // Found -g with an arg + argsum->present |= ARG_GOV; + argsum->governor = (char*)(argv[arg+1]); + //continue; + } + } } } -void set_freq(char* freq, char* core) -{ - set_gov("userspace", core); - set_speed(freq, core); -} - int main(int argc, char *argv[]) { setlocale(LC_ALL,""); + + // TO DO: Not portable bindtextdomain("trayfreq","/usr/share/locale"); + + // TO DO: Needs to be #defined textdomain("trayfreq"); gc_init(); gf_init(); - if(!argv[1]) + argument_summary args; + memset(&args, 0, sizeof(args)); + + // If unusual number of args, give up now + if (argc == 5) { - printf( _("Use -g to set the governor or -f to set the frequency\n") ); - } else if(strcmp(argv[1], "-g") == 0) { - if(!argv[2]) - printf( _("Pass the governor with -g\n") ); - else + get_argument_summary(argc, argv, &args); + + if ( args.present == ( ARG_CORE | ARG_GOV ) ) { - if(!argv[3]) - printf( _("Pass the core with -c\n") ); - else if(strcmp(argv[3], "-c") == 0) - { - if(!argv[4]) - printf( _("Pass the core with -c\n") ); - else - set_gov(argv[2], argv[4]); - } else - printf( _("Pass the core with -c\n") ); + return set_gov(args.governor , args.core); } - } else if(strcmp(argv[1], "-f") == 0) { - if(!argv[2]) + + if ( args.present == ( ARG_CORE | ARG_FREQ ) ) { - printf( _("Pass the frequency with -f\n") ); - } else { - if(!argv[3]) - { - printf( _("Pass the core with -c\n") ); - } else if(strcmp(argv[3], "-c") == 0) - { - if(!argv[4]) - printf( _("Pass the core with -c\n") ); - else - set_freq(argv[2], argv[4]); - } else { - printf( _("Pass the core with -c\n") ); - } + return set_freq(args.frequency , args.core); } - } else { - printf( _("Use -g to set the governor or -f to set the frequency\n") ); } - return 0; + // Fall through to here if no valid argument combination + fprintf(stderr, _("%s {-f frequency|-g governor} -c core\n"), argv[0] ); + return 1; } -- cgit v1.1 From 0975414cc4f0a9deceb02553d174d2d605d0391d Mon Sep 17 00:00:00 2001 From: David Date: Wed, 30 Apr 2014 23:39:41 +1200 Subject: Adding debug stuff --- Makefile | 5 +++-- trayfreq_set/trayfreq_set.c | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 21bb983..b73b3aa 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ MAKE = make CC = gcc INSTALL_PATH=/ +DEBUG= GLIB_CFLAGS = -I/usr/include/glib-2.0 \ @@ -49,14 +50,14 @@ all: trayfreq trayfreq-set lang ######################################################################## # Make trayfreq-set program for setting governors trayfreq-set: - $(CC) -o trayfreq-set $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) + $(CC) -o trayfreq-set $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) $(DEBUG) ######################################################################## ######################################################################## # Make main trayfreq system tray program trayfreq: - $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) + $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) $(DEBUG) ######################################################################## ######################################################################## diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set/trayfreq_set.c index 4f28805..cb5b2c3 100644 --- a/trayfreq_set/trayfreq_set.c +++ b/trayfreq_set/trayfreq_set.c @@ -52,15 +52,18 @@ char write_str_to_file(const char *file, const char *data, const char *core) sprintf(file_path, "/sys/devices/system/cpu/cpu%d/cpufreq/%s", atoi(core), file ); // Try to open file and write data to it - if ( !(fd = fopen(file_path, "w")) ) + if ( (fd = fopen(file_path, "w")) != NULL ) { +#ifdef DEBUG + printf("Writing '%s' to '%s'\n",data,file_path); +#endif fprintf(fd, data); fclose(fd); return 1; } // Fallthrough: File couldn't be opened for writing - printf( _("FAILED: Couldn't open %s for writing\n") , file_path); + fprintf(stderr, _("FAILED: Couldn't open %s for writing\n") , file_path); return 0; } @@ -69,7 +72,6 @@ char write_str_to_file(const char *file, const char *data, const char *core) #define set_freq_min(freq,core) write_str_to_file("scaling_min_freq",freq,core) #define set_speed(freq,core) write_str_to_file("scaling_setspeed",freq,core) #define set_gov(gov,core) write_str_to_file("scaling_governor",gov,core) -#define set_freq(freq,core) set_gov("userspace",core);set_speed(freq,core) void get_argument_summary(int argc, char **argv, argument_summary *argsum) { @@ -83,6 +85,9 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) { if ( strcmp(argv[arg], "-c") == 0 ) { +#ifdef DEBUG + printf("Found -c with arg '%s'\n",argv[arg+1]); +#endif // Found -c with an arg argsum->present |= ARG_CORE; argsum->core = (char*)(argv[arg+1]); @@ -91,6 +96,10 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) if ( strcmp(argv[arg], "-f") == 0 ) { +#ifdef DEBUG + printf("Found -f with arg '%s'\n",argv[arg+1]); +#endif + // Found -f with an arg argsum->present |= ARG_FREQ; argsum->frequency = (char*)(argv[arg+1]); @@ -99,6 +108,9 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) if ( strcmp(argv[arg], "-g") == 0 ) { +#ifdef DEBUG + printf("Found -g with arg '%s'\n",argv[arg+1]); +#endif // Found -g with an arg argsum->present |= ARG_GOV; argsum->governor = (char*)(argv[arg+1]); @@ -112,12 +124,17 @@ int main(int argc, char *argv[]) { setlocale(LC_ALL,""); + // TO DO: Not portable bindtextdomain("trayfreq","/usr/share/locale"); // TO DO: Needs to be #defined textdomain("trayfreq"); +#ifdef DEBUG + printf("Set gettext up\n"); +#endif + gc_init(); gf_init(); @@ -128,17 +145,34 @@ int main(int argc, char *argv[]) if (argc == 5) { get_argument_summary(argc, argv, &args); - + +#ifdef DEBUG + printf("Correct number of command line arguments\n"); + printf("-c: %s -g: %s -f: %s\n", (args.present | ARG_CORE )? "Yes":"No", + (args.present | ARG_GOV )? "Yes":"No", + (args.present | ARG_FREQ )? "Yes":"No" ); + printf("Core: %s\nGov : %s\nFreq: %s\n",args.core,args.governor,args.frequency); +#endif + if ( args.present == ( ARG_CORE | ARG_GOV ) ) { +#ifdef DEBUG + printf("Changing governor\n"); +#endif return set_gov(args.governor , args.core); } if ( args.present == ( ARG_CORE | ARG_FREQ ) ) { - return set_freq(args.frequency , args.core); +#ifdef DEBUG + printf("Changing frequency\n"); +#endif + return set_gov("userspace", args.core) | set_speed(args.frequency, args.core); } } +#ifdef DEBUG + printf("Fell through, showing command usage\n"); +#endif // Fall through to here if no valid argument combination fprintf(stderr, _("%s {-f frequency|-g governor} -c core\n"), argv[0] ); return 1; -- cgit v1.1 From f3d42738f667dd09a4da9cc0a863c44e9cdb3666 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 1 May 2014 12:33:34 +1200 Subject: Debug messages --- Makefile | 7 +++---- bat_tray/bat_tray.c | 46 ++++++++++++++++++++++++++++++---------- bat_tray/bat_tray.h | 4 +--- bool.h | 17 +++++++++++++++ common.c | 2 ++ common.h | 1 + config_file.c | 18 ++++++++++++---- config_file.h | 1 + freq_tray/getcore.c | 9 ++++---- freq_tray/getcore.h | 2 ++ freq_tray/getfreq.c | 30 ++++++++++++++++---------- freq_tray/getgov.c | 28 ++++++++++++++----------- tray.c | 51 ++++++++++++++++++++++++++++++++++++++------- trayfreq.c | 12 ++++++++++- trayfreq_set/trayfreq_set.c | 48 ++++++++++++++---------------------------- 15 files changed, 186 insertions(+), 90 deletions(-) diff --git a/Makefile b/Makefile index b73b3aa..f17655b 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,7 @@ MAKE = make CC = gcc INSTALL_PATH=/ -DEBUG= - +EXTRA_CFLAGS= GLIB_CFLAGS = -I/usr/include/glib-2.0 \ -I/usr/lib/glib-2.0/include @@ -50,14 +49,14 @@ all: trayfreq trayfreq-set lang ######################################################################## # Make trayfreq-set program for setting governors trayfreq-set: - $(CC) -o trayfreq-set $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) $(DEBUG) + $(CC) -o trayfreq-set $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) $(EXTRA_CFLAGS) ######################################################################## ######################################################################## # Make main trayfreq system tray program trayfreq: - $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) $(DEBUG) + $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) $(EXTRA_CFLAGS) ######################################################################## ######################################################################## diff --git a/bat_tray/bat_tray.c b/bat_tray/bat_tray.c index ea7b3c7..0037ce4 100644 --- a/bat_tray/bat_tray.c +++ b/bat_tray/bat_tray.c @@ -53,21 +53,27 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean switch(get_battery_state()) { case STATE_DISCHARGING: - sprintf(msg, _("Discharging (%i%%)"), get_bat_percent()); + debug("Discharging\n"); + sprintf(msg, _("Discharging (%d%%)"), get_bat_percent()); break; case STATE_CHARGING: - sprintf(msg, _("Charging (%i%%)"), get_bat_percent()); + debug("Charging\n"); + sprintf(msg, _("Charging (%d%%)"), get_bat_percent()); break; + case STATE_CHARGED: + debug("Charged\n"); sprintf(msg, _("Fully charged") ); break; default: + debug("Unknown\n"); sprintf(msg, _("Unknown status") ); break; } + debug("Setting tooltip text to '%s'\n",msg); gtk_tooltip_set_text(tooltip, msg); return TRUE; @@ -84,6 +90,8 @@ static gboolean update_icon(gpointer user_data) unsigned int adjusted_percent; gchar adjusted_percent_string[4]; + + // TO DO: do this with rounding and divisio etc if(percent > 90) adjusted_percent=100; else if(percent > 70) @@ -97,7 +105,8 @@ static gboolean update_icon(gpointer user_data) else adjusted_percent=0; - sprintf(adjusted_percent_string, "%i", adjusted_percent); + debug("Rounded/adjusted percentage: %d\n",adjusted_percent); + sprintf(adjusted_percent_string, "%d", adjusted_percent); switch ( get_battery_state() ) { @@ -112,6 +121,8 @@ static gboolean update_icon(gpointer user_data) icon_file = g_strconcat("/usr/share/trayfreq/traybat-charged.png", NULL); break; } + + debug("Setting tray icon to '%s'\n",icon_file); gtk_status_icon_set_from_file(tray, icon_file); return TRUE; } @@ -125,11 +136,10 @@ void bat_tray_init() _BAT_NUM = get_bat_num(); // Set up battery info filenames/paths - sprintf(CHARGE_VALUE_PATH, "/sys/class/power_supply/BAT%i/capacity", _BAT_NUM); - sprintf(CHARGE_STATE_PATH, "/sys/class/power_supply/BAT%i/status", _BAT_NUM); - // NOT USED : sprintf(CURRENT_PATH, "/sys/class/power_supply/BAT%i/charge_now", _BAT_NUM); - + sprintf(CHARGE_VALUE_PATH, "/sys/class/power_supply/BAT%d/capacity", _BAT_NUM); + sprintf(CHARGE_STATE_PATH, "/sys/class/power_supply/BAT%d/status", _BAT_NUM); + debug("Spawning new status icon\n"); tray = gtk_status_icon_new(); gchar* icon_file = g_strconcat("/usr/share/trayfreq/traybat-charged.png", NULL); gtk_status_icon_set_from_file(tray, icon_file); @@ -141,11 +151,13 @@ void bat_tray_init() void bat_tray_show() { + debug("Showing tray\n"); gtk_status_icon_set_visible(tray, TRUE); } void bat_tray_hide() { + debug("Hiding tray\n"); gtk_status_icon_set_visible(tray, FALSE); } @@ -156,14 +168,23 @@ void bat_tray_hide() int get_battery_state() { if (file_has_line(CHARGE_STATE_PATH, "Discharging")) + { + debug("Battery discharging\n"); return STATE_DISCHARGING; + } if (file_has_line(CHARGE_STATE_PATH, "Full")) + { + debug("Battery full\n"); return STATE_CHARGED; + } if (file_has_line(CHARGE_STATE_PATH, "Charging")) - return STATE_CHARGING; - + { + debug("Battery charging\n"); + return STATE_CHARGING; + } + debug("Fallthrough: unknown status\n"); return STATE_UNKNOWN; } @@ -178,16 +199,19 @@ int get_bat_num() unsigned int i; for(i = 0; i < 3; i++) { - sprintf(file, "/sys/class/power_supply/BAT%i/present", i); - + sprintf(file, "/sys/class/power_supply/BAT%d/present", i); + debug("Attempting to open '%s'\n",file); if( (fd = fopen(file, "r")) ) { + debug("Found battery %d\n",i); if (fgetc(fd) == '1') { + debug("Battery %d is present\n",i); fclose(fd); return i; } } } + debug("Fallthrough: couldn't find battery\n"); return -1; } diff --git a/bat_tray/bat_tray.h b/bat_tray/bat_tray.h index 8992b32..1d4c993 100644 --- a/bat_tray/bat_tray.h +++ b/bat_tray/bat_tray.h @@ -20,9 +20,7 @@ #define BAT_TRAY_H #include - - -// already defined in bat_tray.c : #define gb_percent get_int_value_from_file(CHARGE_VALUE_PATH); +#include "../debug.h" #define STATE_CHARGING 0 #define STATE_DISCHARGING 1 diff --git a/bool.h b/bool.h index 4df8b53..fc6031e 100644 --- a/bool.h +++ b/bool.h @@ -1,3 +1,20 @@ +/************************************************************************ + * This file is part of trayfreq-archlinux. * + * * + * trayfreq-archlinux is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * trayfreq-archlinux is distributed in the hope that it will be useful,* + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with trayfreq-archlinux. If not, see * + * . * + ************************************************************************/ #ifndef BOOL_H #define BOOL_H diff --git a/common.c b/common.c index d4d2869..c0e44ef 100644 --- a/common.c +++ b/common.c @@ -71,8 +71,10 @@ int get_int(const char* string) char* first_num; first_num = strpbrk(string, "0123456789"); + debug("first_num: '%s'\n",first_num); if(first_num) return atoi(first_num); + debug("first_num was 0, returning 1\n"); return 1; } diff --git a/common.h b/common.h index 6bb7a40..9eb7716 100644 --- a/common.h +++ b/common.h @@ -20,6 +20,7 @@ #define COMMON_H #include "bool.h" +#include "debug.h" #include #include #include diff --git a/config_file.c b/config_file.c index 5bfbe65..602eb92 100644 --- a/config_file.c +++ b/config_file.c @@ -21,20 +21,30 @@ gboolean config_open(struct config_file* config_file) { if(config_file->key_file) + { + debug("Freeing config_file->keyfile\n"); g_key_file_free(config_file->key_file); + } + debug("Creating new config_file->key_file\n"); config_file->key_file = g_key_file_new(); - gboolean success = g_key_file_load_from_file(config_file->key_file, config_file->file_name, G_KEY_FILE_NONE, NULL); - return success; + return g_key_file_load_from_file( config_file->key_file, + config_file->file_name, + G_KEY_FILE_NONE, + NULL); } void config_close(struct config_file* config_file) { + debug("Freeing key_file with %s value\n",config_file->key_file == NULL? "NULL":"non-NULL"); g_key_file_free(config_file->key_file); } gchar* config_get_key(struct config_file* config_file, const gchar* group_name, const gchar* key_name) { - return g_key_file_get_value(config_file->key_file, group_name, key_name, NULL); -} \ No newline at end of file + return g_key_file_get_value(config_file->key_file, + group_name, + key_name, + NULL); +} diff --git a/config_file.h b/config_file.h index d8e150b..59c7736 100644 --- a/config_file.h +++ b/config_file.h @@ -19,6 +19,7 @@ #ifndef CONFIG_FILE_H #define CONFIG_FILE_H +#include "debug.h" #include struct config_file diff --git a/freq_tray/getcore.c b/freq_tray/getcore.c index a2ee3d3..44b3940 100644 --- a/freq_tray/getcore.c +++ b/freq_tray/getcore.c @@ -22,17 +22,17 @@ #include #include -int NUMBER_OF_CORES; +unsigned int NUMBER_OF_CORES; -static gboolean core_exists(int core) +static gboolean core_exists(unsigned int core) { FILE* fd; char path[80]; char corestr[4]; - sprintf(corestr, "%i", 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); return (gboolean)(fd = fopen(path, "r")); } @@ -40,6 +40,7 @@ void gc_init() { NUMBER_OF_CORES = 0; while(core_exists(++NUMBER_OF_CORES)); + debug("Found %d cores\n",NUMBER_OF_CORES); } diff --git a/freq_tray/getcore.h b/freq_tray/getcore.h index fc1fc8d..43dcd12 100644 --- a/freq_tray/getcore.h +++ b/freq_tray/getcore.h @@ -19,6 +19,8 @@ #ifndef GETCORE_H #define GETCORE_H +#include "../debug.h" + void gc_init(); int gc_number(); diff --git a/freq_tray/getfreq.c b/freq_tray/getfreq.c index 02970b4..4b00775 100644 --- a/freq_tray/getfreq.c +++ b/freq_tray/getfreq.c @@ -31,17 +31,21 @@ int NUMBER_OF_AVAILABLE_FREQUENCIES; void gf_init() { + // TO DO : get rid of magic constants gchar freq_string[500]; int i = 0; int j = 0; for(i = 0; i < gc_number(); ++i) { - memset(freq_string, 0, 500); + memset(freq_string, '\0', 500); // Get available governor freqs. If no governor, try next cpu if (gf_available(i, freq_string, 500) == -1) + { + debug("Couldn't find gov on core %d\n",i); continue; + } /* go through every frequency in freq_string */ j = 0; @@ -49,7 +53,7 @@ void gf_init() gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); while(end_of_curr) { - memset(AVAILABLE_FREQUENCIES[i][j], 0, 13); + memset(AVAILABLE_FREQUENCIES[i][j], '\0', 13); memmove(AVAILABLE_FREQUENCIES[i][j], curr, end_of_curr - curr); curr = end_of_curr+1; @@ -58,6 +62,7 @@ void gf_init() } } NUMBER_OF_AVAILABLE_FREQUENCIES = j; + debug("Found %d frequencies\n",j); } int gf_current(int core) @@ -65,20 +70,21 @@ int gf_current(int core) FILE* fd; char buff[13]; char path[80]; - char corestr[4]; int freq; - sprintf(corestr, "%i", core); - - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", core); if(!(fd = fopen(path, "r"))) - return -1; + { + debug("Couldn't open '%s'\n",path); + return -1; + } fgets(buff, 13, fd); freq = atoi(buff); fclose(fd); + debug("Found freq %d on core %d\n",freq,core); return freq; } @@ -86,14 +92,14 @@ int gf_available(int core, char* out, int size) { FILE* fd; char path[80]; - char corestr[4]; - - sprintf(corestr, "%i", core); - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_available_frequencies", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_frequencies", core); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); @@ -111,6 +117,8 @@ void gf_get_frequency_label(int freq, char* out) sprintf(out, "%.2f GHz", freq/pow(10, i-1)); else sprintf(out, "%.2d MHz", freq/1000); + + debug("Prepared freq label '%s' for freq %d\n",out,freq); } char* gf_freqa(int core, int index) diff --git a/freq_tray/getgov.c b/freq_tray/getgov.c index 8fe44a5..181ad41 100644 --- a/freq_tray/getgov.c +++ b/freq_tray/getgov.c @@ -39,18 +39,18 @@ void gg_init() memset(gov_string, '\0', 500); gg_available(i, gov_string, 500); - /* go through every governor in gov_string */ + // go through every governor in gov_string j = 0; gchar* curr = &gov_string[0]; gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); while(end_of_curr) { - memset(AVAILABLE_GOVERNORS[i][j], '\0', 13); - memmove(AVAILABLE_GOVERNORS[i][j], curr, end_of_curr - curr); + memset(AVAILABLE_GOVERNORS[i][j], '\0', 13); + memmove(AVAILABLE_GOVERNORS[i][j], curr, end_of_curr - curr); - curr = end_of_curr+1; - end_of_curr = g_strstr_len(curr, strlen(curr), " "); - ++j; + curr = end_of_curr+1; + end_of_curr = g_strstr_len(curr, strlen(curr), " "); + ++j; } } NUMBER_OF_AVAILABLE_GOVERNORS = j; @@ -67,14 +67,18 @@ int gg_current(int core, char* out, int size) sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_governor", corestr); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); - - /* remove newline at the end */ + // Chomp gchar* newline = g_strrstr(out, "\n"); *newline = '\0'; + debug("Current gov for core %d is '%s'\n",core,out); + fclose(fd); return 0; } @@ -83,14 +87,14 @@ int gg_available(int core, char* out, int size) { FILE* fd; char path[80]; - char corestr[4]; - sprintf(corestr, "%i", core); - - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_available_governors", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors", core); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); diff --git a/tray.c b/tray.c index eb6c65a..05465c4 100644 --- a/tray.c +++ b/tray.c @@ -29,6 +29,7 @@ GtkWidget* checked_menu_item; static void freq_menu_item_toggled(GtkCheckMenuItem* item, gpointer data) { + debug("[checking in]\n"); if(gtk_check_menu_item_get_active(item)) { checked_menu_item = GTK_WIDGET(item); @@ -41,6 +42,7 @@ static void freq_menu_item_toggled(GtkCheckMenuItem* item, gpointer data) static void gov_menu_item_toggled(GtkCheckMenuItem* item, gpointer data) { + debug("[checking in]\n"); if(gtk_check_menu_item_get_active(item)) { checked_menu_item = GTK_WIDGET(item); @@ -64,11 +66,13 @@ static gboolean governor_exists(gchar* governor) static void remove_menu_item(GtkWidget* menu_item, gpointer data) { + debug("Destroying menu_item\n"); gtk_widget_destroy(menu_item); } static void tray_clear_menu() { + debug("Clearing the menu\n"); GtkContainer* cont = GTK_CONTAINER(menu); gtk_container_foreach(cont, remove_menu_item, NULL); menu_items = NULL; @@ -76,6 +80,7 @@ static void tray_clear_menu() static void tray_init_menu() { + debug("Spawning new menu"); menu = gtk_menu_new(); } @@ -93,43 +98,59 @@ static void tray_generate_menu() gint current_frequency = gf_current(0); - /* append the frequencies */ + // Add available frequencies for(i = 0; i < gf_number(); ++i) { memset(label, '\0', 20); gf_get_frequency_label(gf_freqi(0, i), label); + debug("Got freq label '%s', i=%d\n",label,i); GtkWidget* item = gtk_radio_menu_item_new_with_label(menu_items, label); menu_items = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM (item)); if(g_strcmp0(current_governor, "userspace") == 0 && gf_freqi(0, i) == current_frequency) + { + debug("This freq is current freq, ticking radio button\n"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); + } + debug("Setting connection/callback\n"); g_signal_connect(G_OBJECT(item), "toggled", GTK_SIGNAL_FUNC(freq_menu_item_toggled), GINT_TO_POINTER(gf_freqi(0, i))); + + debug("Adding item to menu\n"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); } - /* append the seperator */ + // Add a seperator + debug("Adding separator\n"); GtkWidget* seperator = gtk_separator_menu_item_new(); gtk_menu_append(menu, seperator); - /* append the governors*/ + // Add available governors for(i = 0; i < gg_number(); i++) { if(g_strcmp0(gg_gov(0, i), "userspace") == 0) - continue; + { + debug("Gov is userspace, not adding\n"); + continue; + } GtkWidget* item = gtk_radio_menu_item_new_with_label(menu_items, gg_gov(0, i)); menu_items = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM (item)); if(g_strcmp0(gg_gov(0, i), current_governor) == 0) { + debug("Governor is current one, ticking radio button\n"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); } - + + debug("Adding callback"); g_signal_connect(G_OBJECT(item), "toggled", GTK_SIGNAL_FUNC(gov_menu_item_toggled), gg_gov(0, i)); + + debug("Adding item to menu\n"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); } + debug("Showing menu\n"); gtk_widget_show_all(menu); } @@ -147,6 +168,7 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean switch ( get_battery_state() ) { case STATE_DISCHARGING: + debug("Discharging\n"); if(_DEFAULT_BAT_GOV) { for(i = 0; i < gc_number(); ++i) @@ -156,6 +178,7 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean case STATE_CHARGING: case STATE_FULL: + debug("Charging/Full\n"); if(_DEFAULT_AC_GOV) { for(i = 0; i < gc_number(); ++i) @@ -170,11 +193,13 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean for(i = 0; i < gc_number(); ++i) { + debug("Adding CPU%i's frequency\n",i); 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"); } + debug("Setting tooltip text\n"); tray_set_tooltip(msg); gtk_tooltip_set_text(tooltip, tooltip_text); @@ -183,12 +208,14 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean static void popup_menu(GtkStatusIcon* statuc_icon,guint button,guint activate_time,gpointer data) { + debug("Spawning popup menu\n"); tray_generate_menu(); gtk_menu_popup(GTK_MENU(menu),NULL,NULL,gtk_status_icon_position_menu,tray,button,activate_time); } static gboolean update_icon(gpointer user_data) { + debug("Updating icon\n"); tray_update_icon_percent(); return TRUE; } @@ -210,24 +237,28 @@ void tray_init() if(_DEFAULT_FREQ) { for(i = 0; i < gc_number(); ++i) - { si_freq(atoi(_DEFAULT_FREQ), i); - } } tray = gtk_status_icon_new(); gchar* icon_file = g_strconcat("/usr/share/trayfreq/cpufreq-0.png", NULL); + + debug("Setting icon to '%s'\n",icon_file); gtk_status_icon_set_from_file(tray, icon_file); - gtk_status_icon_set_has_tooltip (tray, TRUE); + gtk_status_icon_set_has_tooltip(tray, TRUE); + + debug("Setting up callbacks\n"); 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); + debug("Adding timeout\n"); g_timeout_add(1000, update_icon, NULL); tray_init_menu(); } void tray_set_tooltip(const gchar* msg) { + debug("Setting up toolip var with text '%s'\n",msg); memset(tooltip_text, '\0', TOOLTIP_TEXT_SIZE); memmove(tooltip_text, msg, strlen(msg)); } @@ -256,11 +287,13 @@ void tray_update_icon_percent() } } + debug("Rounded/adjusted bat percentage: %d\n",adjusted_percent); /* convert the int to a string */ gchar adjusted_percent_string[] = {'\0', '\0', '\0', '\0'}; sprintf(adjusted_percent_string, "%i", adjusted_percent); gchar* file = g_strconcat("/usr/share/trayfreq/cpufreq-", adjusted_percent_string, ".png", NULL); + debug("Setting tray icon to '%s'\n",file); gtk_status_icon_set_from_file(tray, file); g_free(file); @@ -268,11 +301,13 @@ void tray_update_icon_percent() void tray_show() { + debug("Showing tray\n"); gtk_status_icon_set_visible(tray, TRUE); } void tray_hide() { + debug("Hiding tray"); gtk_status_icon_set_visible(tray, FALSE); } diff --git a/trayfreq.c b/trayfreq.c index e7c8933..e3b925e 100644 --- a/trayfreq.c +++ b/trayfreq.c @@ -24,6 +24,7 @@ #include "freq_tray/getgov.h" #include "config_file.h" #include "defaults.h" +#include "debug.h" #include #include @@ -43,14 +44,17 @@ void config_init() config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.config", NULL); + // Check if ~/.trayfreq.config exists if( (fd = fopen(config.file_name, "r")) ) { // If file exists, close it, set param to TRUE + debug("Found '%s'\n",config.file_name); fclose(fd); home_config_exists = TRUE; } else { // If file didn't exist, it's not open (don't close it), free filename var, set param to FALSE + debug("Didn't find '%s'\n",config.file_name); g_free(config.file_name); home_config_exists = FALSE; } @@ -62,6 +66,7 @@ void config_init() if(!success) { + debug("Couldn't open '%s' for reading\n",config.file_name); g_warning(_("Failed to open config files!\n")); return; } @@ -100,10 +105,12 @@ int main(int argc, char** argv) setlocale(LC_ALL, ""); bindtextdomain("trayfreq","/usr/share/locale"); textdomain("trayfreq"); + debug("Set gettext up\n"); if(!gtk_init_check(&argc, &argv)) { - g_error(_("GTK Error: gtk_init_check returned FALSE.\nBailing.") ); + debug("Couldn't start gtk\n"); + g_error( _("GTK Error: gtk_init_check returned FALSE.\nBailing.") ); return 1; } config_init(); @@ -116,10 +123,13 @@ int main(int argc, char** argv) // Show battery tray only if we're supposed to if(SHOW_BATTERY) { + debug("Showing battery info this time around\n"); bat_tray_init(); bat_tray_show(); } + debug("Passing control to Gtk\n"); gtk_main(); + debug("Exiting main()\n"); return 0; } diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set/trayfreq_set.c index cb5b2c3..0d65138 100644 --- a/trayfreq_set/trayfreq_set.c +++ b/trayfreq_set/trayfreq_set.c @@ -27,6 +27,7 @@ #include "../freq_tray/getfreq.h" #include "../freq_tray/getcore.h" +#include "../debug.h" #define FILE_PATH_STRING_SIZE 100 @@ -54,9 +55,7 @@ char write_str_to_file(const char *file, const char *data, const char *core) // Try to open file and write data to it if ( (fd = fopen(file_path, "w")) != NULL ) { -#ifdef DEBUG - printf("Writing '%s' to '%s'\n",data,file_path); -#endif + debug("Writing '%s' to '%s'\n",data,file_path); fprintf(fd, data); fclose(fd); return 1; @@ -85,10 +84,8 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) { if ( strcmp(argv[arg], "-c") == 0 ) { -#ifdef DEBUG - printf("Found -c with arg '%s'\n",argv[arg+1]); -#endif // Found -c with an arg + debug("Found -c with arg '%s'\n",argv[arg+1]); argsum->present |= ARG_CORE; argsum->core = (char*)(argv[arg+1]); continue; @@ -96,11 +93,8 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) if ( strcmp(argv[arg], "-f") == 0 ) { -#ifdef DEBUG - printf("Found -f with arg '%s'\n",argv[arg+1]); -#endif - // Found -f with an arg + debug("Found -f with arg '%s'\n",argv[arg+1]); argsum->present |= ARG_FREQ; argsum->frequency = (char*)(argv[arg+1]); continue; @@ -108,10 +102,8 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) if ( strcmp(argv[arg], "-g") == 0 ) { -#ifdef DEBUG - printf("Found -g with arg '%s'\n",argv[arg+1]); -#endif // Found -g with an arg + debug("Found -g with arg '%s'\n",argv[arg+1]); argsum->present |= ARG_GOV; argsum->governor = (char*)(argv[arg+1]); //continue; @@ -131,9 +123,7 @@ int main(int argc, char *argv[]) // TO DO: Needs to be #defined textdomain("trayfreq"); -#ifdef DEBUG - printf("Set gettext up\n"); -#endif + debug("Set gettext up\n"); gc_init(); gf_init(); @@ -146,34 +136,28 @@ int main(int argc, char *argv[]) { get_argument_summary(argc, argv, &args); -#ifdef DEBUG - printf("Correct number of command line arguments\n"); - printf("-c: %s -g: %s -f: %s\n", (args.present | ARG_CORE )? "Yes":"No", - (args.present | ARG_GOV )? "Yes":"No", - (args.present | ARG_FREQ )? "Yes":"No" ); - printf("Core: %s\nGov : %s\nFreq: %s\n",args.core,args.governor,args.frequency); -#endif + debug("Correct number of command line arguments\n"); + debug("-c: %s -g: %s -f: %s\n", (args.present | ARG_CORE )? "Yes":"No", + (args.present | ARG_GOV )? "Yes":"No", + (args.present | ARG_FREQ )? "Yes":"No" ); + debug("Core: %s\n",args.core); + debug("Gov : %s\n",args.governor); + debug("Freq: %s\n",args.frequency); if ( args.present == ( ARG_CORE | ARG_GOV ) ) { -#ifdef DEBUG - printf("Changing governor\n"); -#endif + debug("Changing governor\n"); return set_gov(args.governor , args.core); } if ( args.present == ( ARG_CORE | ARG_FREQ ) ) { -#ifdef DEBUG - printf("Changing frequency\n"); -#endif + debug("Changing frequency\n"); return set_gov("userspace", args.core) | set_speed(args.frequency, args.core); } } -#ifdef DEBUG - printf("Fell through, showing command usage\n"); -#endif // Fall through to here if no valid argument combination + debug("Fell through, showing command usage\n"); fprintf(stderr, _("%s {-f frequency|-g governor} -c core\n"), argv[0] ); return 1; } -- cgit v1.1 From 6b9bb76b232e2b00ffdae6b8a50c5f2c9540b4f2 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 1 May 2014 12:34:41 +1200 Subject: Added mussing header --- debug.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 debug.h diff --git a/debug.h b/debug.h new file mode 100644 index 0000000..571d271 --- /dev/null +++ b/debug.h @@ -0,0 +1,34 @@ +/************************************************************************ + * This file is part of trayfreq-archlinux. * + * * + * trayfreq-archlinux is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * trayfreq-archlinux is distributed in the hope that it will be useful,* + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with trayfreq-archlinux. If not, see * + * . * + ************************************************************************/ + +/* + This file makes debug macros into empty space if debug mode's not enabled. + Otherwise it will make debug macro calls into appropriate printf()s +*/ + +#ifdef DEBUG + #include + // Stringification of line number + #define STRING2(x) #x + #define STRING(x) STRING2(x) + #define STR_LINE STRING(__LINE__) + // + #define debug(...) printf("DEBUG: "__FILE__":"STR_LINE" --- "__VA_ARGS__) +#else + #define debug(...); +#endif -- cgit v1.1 From ded92caed9d35256e08b99ec3022cb9c57f301e4 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 1 May 2014 12:46:25 +1200 Subject: Removed compiled version of gettext thingy --- lc/fr.mo | Bin 1029 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lc/fr.mo diff --git a/lc/fr.mo b/lc/fr.mo deleted file mode 100644 index 754a8d3..0000000 Binary files a/lc/fr.mo and /dev/null differ -- cgit v1.1 From 63dc961871ecae300350a3b5568425344b13f56d Mon Sep 17 00:00:00 2001 From: David Date: Thu, 1 May 2014 13:10:23 +1200 Subject: Updated french translation --- lc/fr.po | 81 +++++++++++++++++++++++++--------------------------------------- 1 file changed, 32 insertions(+), 49 deletions(-) diff --git a/lc/fr.po b/lc/fr.po index 9bd6ade..9e237ca 100644 --- a/lc/fr.po +++ b/lc/fr.po @@ -1,86 +1,69 @@ -# French translations for PACKAGE package -# Traductions françaises du paquet PACKAGE. -# Copyright (C) 2014 THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# , 2014. +# 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 , YEAR. # +#, fuzzy msgid "" msgstr "" -"Project-Id-Version: trayfreq 4\n" +"Project-Id-Version: trayfreq-archlinux 0.5\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-04-27 12:49+1200\n" -"PO-Revision-Date: 2014-04-27 12:49+1200\n" -"Last-Translator: \n" -"Language-Team: French\n" +"POT-Creation-Date: 2014-05-01 13:02+1200\n" +"PO-Revision-Date: 2014-05-01 13:08+1200\n" +"Last-Translator: David Phillips \n" +"Language-Team: French \n" "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: tray.c:183 +#: tray.c:192 #, c-format msgid "Governor: %s\n" msgstr "Profil: %s\n" -#: tray.c:189 +#: tray.c:199 #, c-format msgid "CPU%i: %s%s" msgstr "CPU%i: %s%s" -#: trayfreq.c:67 +#: trayfreq.c:70 msgid "Failed to open config files!\n" -msgstr "" +msgstr "Pouvais pas ouvrier les fichiers config !\n" -#: trayfreq.c:112 +#: trayfreq.c:113 msgid "" "GTK Error: gtk_init_check returned FALSE.\n" "Bailing." -msgstr "" +msgstr "Erreur: gtk_init_check a retourné FALSE.\n" +"Je part" -#: bat_tray/bat_tray.c:56 +#: bat_tray/bat_tray.c:57 #, c-format -msgid "Discharging (%i%%)" -msgstr "" +msgid "Discharging (%d%%)" +msgstr "En décharge (%d%%)" -#: bat_tray/bat_tray.c:60 +#: bat_tray/bat_tray.c:62 #, c-format -msgid "Charging (%i%%)" -msgstr "" +msgid "Charging (%d%%)" +msgstr "En charge (%d%%)" -#: bat_tray/bat_tray.c:63 +#: bat_tray/bat_tray.c:67 #, c-format msgid "Fully charged" -msgstr "Complétment chargée" +msgstr "Complétement chargée" -#: bat_tray/bat_tray.c:67 +#: bat_tray/bat_tray.c:72 #, c-format msgid "Unknown status" -msgstr "" +msgstr "Statut inconnu" -#: trayfreq_set/trayfreq_set.c:42 +#: trayfreq_set/trayfreq_set.c:65 #, c-format msgid "FAILED: Couldn't open %s for writing\n" -msgstr "ERREUR: Pouvais pas ecrit à %s\n" - -#: trayfreq_set/trayfreq_set.c:118 trayfreq_set/trayfreq_set.c:154 -#, c-format -msgid "Use -g to set the governor or -f to set the frequency\n" -msgstr "Utiliser -g pour activer les profils ou -f pour activer les fréquences\n" - -#: trayfreq_set/trayfreq_set.c:121 -#, c-format -msgid "Pass the governor with -g\n" -msgstr "Indiquer le profil avec un -c\n" - -#: trayfreq_set/trayfreq_set.c:125 trayfreq_set/trayfreq_set.c:129 -#: trayfreq_set/trayfreq_set.c:133 trayfreq_set/trayfreq_set.c:142 -#: trayfreq_set/trayfreq_set.c:146 trayfreq_set/trayfreq_set.c:150 -#, c-format -msgid "Pass the core with -c\n" -msgstr "Indiquer le core avec un -c\n" +msgstr "ERREUR: Peut pas écrire à %s\n" -#: trayfreq_set/trayfreq_set.c:138 +#: trayfreq_set/trayfreq_set.c:161 #, c-format -msgid "Pass the frequency with -f\n" -msgstr "Indiquer la fréquence avec un -f\n" +msgid "%s {-f frequency|-g governor} -c core\n" +msgstr "%s {-f fréquence|-g profil} -c core\n" -- cgit v1.1 From fe07b9907dbc5191e7a78c2dde7f5bbed4cfacfa Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:42:02 +1200 Subject: Insignificant tweak --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index f17655b..9905ac1 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,7 @@ trayfreq_set_SOURCES = trayfreq_set/trayfreq_set.c \ all: trayfreq trayfreq-set lang ######################################################################## + ######################################################################## # Make trayfreq-set program for setting governors trayfreq-set: @@ -59,12 +60,14 @@ trayfreq: $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) $(EXTRA_CFLAGS) ######################################################################## + ######################################################################## # Make language files lang: msgfmt -c -o lc/fr.mo lc/fr.po ######################################################################## + ######################################################################## # Remove generated files clean: -- cgit v1.1 From 8913f121822af36e9e099c1b2d8e64f7dab0d863 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:22:22 +1200 Subject: Done --- config_file.c | 6 +++-- defaults.c | 11 ++++----- defaults.h | 3 ++- freq_tray/getcore.c | 2 +- trayfreq.c | 42 ++++++++++++++--------------------- trayfreq_set/trayfreq_set_interface.c | 15 ++++++++++--- trayfreq_set/trayfreq_set_interface.h | 2 ++ 7 files changed, 44 insertions(+), 37 deletions(-) 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/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 +#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/trayfreq.c b/trayfreq.c index e3b925e..7e5d8d4 100644 --- a/trayfreq.c +++ b/trayfreq.c @@ -63,39 +63,31 @@ void config_init() config.file_name = g_strconcat("/usr/share/trayfreq/trayfreq.config", 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 #include #include 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); -- cgit v1.1 From cd07fec6d1158b67897482c4901fd88878847c86 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:31:46 +1200 Subject: Changed config file name, spruced default config up --- Makefile | 2 +- data/trayfreq.config | 9 --------- trayfreq.c | 4 ++-- 3 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 data/trayfreq.config diff --git a/Makefile b/Makefile index 9905ac1..7c34210 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,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/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/trayfreq.c b/trayfreq.c index 7e5d8d4..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,7 +60,7 @@ 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) -- cgit v1.1 From 3c8bdd937f224c0b02547ecbfac44e349c2235ad Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:32:06 +1200 Subject: I always forget to add files when I move them --- data/trayfreq.conf | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 data/trayfreq.conf 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 -- cgit v1.1 From 78d218286e972f832b7b0c2e48fcbd096a56653b Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:40:21 +1200 Subject: Cured fuzz --- lc/fr.po | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 , YEAR. +# David Phillips , 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." -- cgit v1.1 From c2e45c577c6b9838bb525fe6f7dfd191297eddd0 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:47:56 +1200 Subject: Makefile nicety --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7c34210..82b94ec 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,14 @@ MAKE = make CC = gcc INSTALL_PATH=/ -EXTRA_CFLAGS= + +ifdef DEBUG + EXTRA_CFLAGS+=-DDEBUG +else + EXTRA_CFLAGS= +endif + + GLIB_CFLAGS = -I/usr/include/glib-2.0 \ -I/usr/lib/glib-2.0/include -- cgit v1.1 From 70e630e07304180da585d7dc65df88679f700012 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 May 2014 11:59:46 +1200 Subject: Changed installation autostart thing in readme --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 66f89a1..8c66e27 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,18 @@ 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. +`make install` will copy a .desktop file to /etc/xdg/autostart, meaning that all xdg-compliant window managers should start it automatically when Bob logs in. +Bob's WM starts these programs as root, thus he is fully able to change the governor. + +Alice uses a non-xdg-compliant WM (e.g. dwm) so trayfreq is run as the user `alice`. +She doesn't have permission to write to the files under `/sys/` so trayfreq can't change the governor. +Alice needs to make trayfreq run `trayfreq-set` through sudo. +This can be done in the configuration file. +Then, she also needs to give herself passwordless permission to run `trayfreq-set` through sudo: -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 + alice ALL = NOPASSWD: /usr/bin/trayfreq-set # ... Simple. -- cgit v1.1 From 1efe7e3c4da1dc79cc59c2fe0c9fe002c45f600d Mon Sep 17 00:00:00 2001 From: David Date: Fri, 9 May 2014 21:09:23 +1200 Subject: Updated default config file --- data/trayfreq.conf | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/data/trayfreq.conf b/data/trayfreq.conf index 59dc4d8..ad6abcf 100644 --- a/data/trayfreq.conf +++ b/data/trayfreq.conf @@ -5,9 +5,12 @@ [battery] ## Uncomment to hide battery icon -- useful for desktop PCs +## Set to anything (or leave unset/commented out) to show battery icon # show=0 -## Governor to use for all cores when on battery power +## Name of the governor to use for all cores when on battery power +## Get a space-separated list of available governors from +## /sys/devices/system/cpu/cpu{{CORE_NUMBER}}/cpufreq/scaling_available_governors # governor=powersave [ac] @@ -20,8 +23,10 @@ # default=ondemand -## The frequency to set the CPU to when trayfreq starts [frequency] +## The frequency to set the CPU to when trayfreq starts +## Get a space-separated list of available frequencies from +## /sys/devices/system/cpu/cpu{{CORE_NUMBER}}/cpufreq/scaling_available_frequencies # default=800000 -- cgit v1.1 From be9227dfcfdba5362cf1acba1033c11b7c33f346 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 10 May 2014 11:34:17 +1200 Subject: Fixed Makefile clean procedure with regards to lang stuff --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 82b94ec..8c86ef2 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ lang: ######################################################################## # Remove generated files clean: - rm -f trayfreq trayfreq-set lang/*.mo + rm -f trayfreq trayfreq-set lc/*.mo ######################################################################## -- cgit v1.1 From bf04ee460a3221f8d4b6caa628a5820375642545 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 10 May 2014 11:32:45 +1200 Subject: First preparations for config reloading on-the-fly --- Makefile | 3 ++- reload.c | 22 ++++++++++++++++++++++ reload.h | 21 +++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 reload.c create mode 100644 reload.h diff --git a/Makefile b/Makefile index 8c86ef2..3f7d098 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,8 @@ trayfreq_SOURCES = freq_tray/getcore.c \ config_file.c \ defaults.c \ bat_tray/bat_tray.c \ - common.c + common.c \ + reload.c trayfreq_set_CFLAGS = $(GLIB_CFLAGS) -Wall -D_=gettext trayfreq_set_LDFLAGS = $(GLIB_LIBS) -lm diff --git a/reload.c b/reload.c new file mode 100644 index 0000000..fcc5ca9 --- /dev/null +++ b/reload.c @@ -0,0 +1,22 @@ +/************************************************************************ + * This file is part of trayfreq-archlinux. * + * * + * trayfreq-archlinux is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * trayfreq-archlinux is distributed in the hope that it will be useful,* + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with trayfreq-archlinux. If not, see * + * . * + ************************************************************************/ + +void reload_config() +{ + printf("USR1\n"); +} diff --git a/reload.h b/reload.h new file mode 100644 index 0000000..6ca7cf4 --- /dev/null +++ b/reload.h @@ -0,0 +1,21 @@ +/************************************************************************ + * This file is part of trayfreq-archlinux. * + * * + * trayfreq-archlinux is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * trayfreq-archlinux is distributed in the hope that it will be useful,* + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * *