diff options
author | David <dbphillipsnz@gmail.com> | 2014-05-10 21:30:16 +1200 |
---|---|---|
committer | David <dbphillipsnz@gmail.com> | 2014-05-10 21:30:16 +1200 |
commit | 2f363ccbee35d265866f04ba6ca34ab2e0ebe4d6 (patch) | |
tree | 00dfe6457aa54bad46adea2894df365246d6ecef | |
parent | c6b5a3477b87ced86356813a578c19f6b345008b (diff) | |
download | paramano-2f363ccbee35d265866f04ba6ca34ab2e0ebe4d6.tar.xz |
Header/includes tidy-up
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | bat_tray.c | 6 | ||||
-rw-r--r-- | bat_tray.h | 4 | ||||
-rw-r--r-- | common.c | 6 | ||||
-rw-r--r-- | common.h | 5 | ||||
-rw-r--r-- | config_file.c | 1 | ||||
-rw-r--r-- | config_file.h | 1 | ||||
-rw-r--r-- | defaults.h | 4 | ||||
-rw-r--r-- | getcore.c | 2 | ||||
-rw-r--r-- | getfreq.c | 9 | ||||
-rw-r--r-- | reload.c | 6 | ||||
-rw-r--r-- | reload.h | 4 | ||||
-rw-r--r-- | tray.c | 42 | ||||
-rw-r--r-- | tray.h | 33 | ||||
-rw-r--r-- | trayfreq.c | 107 | ||||
-rw-r--r-- | trayfreq.h | 19 | ||||
-rw-r--r-- | trayfreq_set_interface.c | 2 | ||||
-rw-r--r-- | trayfreq_set_interface.h | 2 | ||||
-rw-r--r-- | widget_manager.c | 36 | ||||
-rw-r--r-- | widget_manager.h | 30 |
20 files changed, 124 insertions, 199 deletions
@@ -21,8 +21,8 @@ DEPS = bat_tray.h \ reload.h \ trayfreq.h \ tray.h \ - trayfreq_set_interface.h \ - widget_manager.h + trayfreq_set_interface.h +# widget_manager.h GLIB_CFLAGS = -I/usr/include/glib-2.0 \ @@ -20,10 +20,10 @@ #include "bat_tray.h" #include <gtk/gtk.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> #include <libintl.h> +#include "debug.h" +#include "common.h" + static GtkStatusIcon* tray; @@ -19,10 +19,6 @@ #ifndef BAT_TRAY_H #define BAT_TRAY_H -#include <glib.h> -#include "debug.h" -#include "common.h" - #define STATE_CHARGING 0 #define STATE_DISCHARGING 1 #define STATE_CHARGED 2 @@ -18,6 +18,12 @@ #include "common.h" +#include "debug.h" /* debug() */ + +#include <stdio.h> /* fopen, fgets, printf */ +#include <stdlib.h> /* atoi */ +#include <string.h> /* lots of functions */ + /*********************************************************************** * Gets integer value from first line in file **********************************************************************/ @@ -20,11 +20,6 @@ #define COMMON_H #include "bool.h" -#include "debug.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - int get_int_value_from_file(const char* filename); int get_int(const char* string); diff --git a/config_file.c b/config_file.c index a62f094..784956b 100644 --- a/config_file.c +++ b/config_file.c @@ -17,6 +17,7 @@ ************************************************************************/ #include "config_file.h" +#include "debug.h" gboolean config_open(struct config_file* config_file) { diff --git a/config_file.h b/config_file.h index 59c7736..d8e150b 100644 --- a/config_file.h +++ b/config_file.h @@ -19,7 +19,6 @@ #ifndef CONFIG_FILE_H #define CONFIG_FILE_H -#include "debug.h" #include <glib.h> struct config_file @@ -19,8 +19,8 @@ #ifndef DEFAULTS_H #define DEFAULTS_H -#include "bool.h" -#include <stdlib.h> +#include "bool.h" /* boolean types */ +#include <stdlib.h> /* NULL */ char* _DEFAULT_GOV; char* _DEFAULT_FREQ; @@ -43,8 +43,6 @@ void gc_init() debug("Found %d cores\n",NUMBER_OF_CORES); } - -/* to do */ int gc_number() { return NUMBER_OF_CORES; @@ -18,7 +18,6 @@ #include "getfreq.h" #include "getcore.h" -#include "math.h" #include <stdio.h> #include <stdlib.h> @@ -109,12 +108,8 @@ int gf_available(int core, char* out, int size) void gf_get_frequency_label(int freq, char* out) { - int i = 0; - while(freq/pow(10, i) >= 1) - ++i; - - if(i == 7) - sprintf(out, "%.2f GHz", freq/pow(10, i-1)); + if(freq >= 1000000) // >= 1 million KHz (1GHz) + sprintf(out, "%.2f GHz", ((float)freq/1000000) ); else sprintf(out, "%.2d MHz", freq/1000); @@ -17,6 +17,12 @@ ************************************************************************/ #include "reload.h" +#include "bat_tray.h" +#include "tray.h" +#include "trayfreq.h" +#include "defaults.h" +#include "debug.h" +#include <stdio.h> void reload_config() { @@ -18,10 +18,6 @@ #ifndef RELOAD_H #define RELOAD_H -#include "trayfreq.h" -#include "defaults.h" -#include "bat_tray.h" -#include <stdio.h> void reload_config(); #endif @@ -18,10 +18,26 @@ #include "tray.h" +//#include "widget_manager.h" +#include "getfreq.h" +#include "getcore.h" +#include "getgov.h" +#include "trayfreq_set_interface.h" +#include "bat_tray.h" +#include "defaults.h" + +#include <glib.h> +#include <gtk/gtk.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <libintl.h> + + #define TOOLTIP_TEXT_SIZE 500 GtkStatusIcon* tray; -gchar tooltip_text[TOOLTIP_TEXT_SIZE]; +char tooltip_text[TOOLTIP_TEXT_SIZE]; GtkWidget* menu; GSList* menu_items; @@ -46,7 +62,7 @@ static void gov_menu_item_toggled(GtkCheckMenuItem* item, gpointer data) if(gtk_check_menu_item_get_active(item)) { checked_menu_item = GTK_WIDGET(item); - gchar* gov = (gchar*)data; + char* gov = (char*)data; int i = 0; for(i = 0; i < gc_number(); ++i) si_gov(gov, i); @@ -89,10 +105,10 @@ static void tray_generate_menu() tray_clear_menu(); gg_init(); - gchar label[20]; + char label[20]; int i = 0; - gchar current_governor[20]; + char current_governor[20]; memset(current_governor, '\0', sizeof(current_governor) ); gg_current(0, current_governor, sizeof(current_governor) ); @@ -156,9 +172,9 @@ 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[TOOLTIP_TEXT_SIZE]; - gchar current_governor[20]; - gchar label[20]; + char msg[TOOLTIP_TEXT_SIZE]; + char current_governor[20]; + char label[20]; int i = 0; memset(msg, '\0', sizeof(msg)); @@ -246,7 +262,7 @@ void tray_init() { tray_set_defaults(); tray = gtk_status_icon_new(); - gchar* icon_file = g_strconcat("/usr/share/trayfreq/cpufreq-0.png", NULL); + char* 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); @@ -261,7 +277,7 @@ void tray_init() tray_init_menu(); } -void tray_set_tooltip(const gchar* msg) +void tray_set_tooltip(const char* msg) { debug("Setting up toolip var with text '%s'\n",msg); memset(tooltip_text, '\0', TOOLTIP_TEXT_SIZE); @@ -294,10 +310,10 @@ 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'}; + char 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); + char* 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); @@ -316,12 +332,12 @@ void tray_hide() gtk_status_icon_set_visible(tray, FALSE); } -gboolean tray_visible() +bool tray_visible() { return gtk_status_icon_get_visible(tray); } -gboolean tray_embedded() +bool tray_embedded() { return gtk_status_icon_is_embedded(tray); } @@ -19,30 +19,15 @@ #ifndef TRAY_H #define TRAY_H -#include <glib.h> +#include "bool.h" -#include "widget_manager.h" -#include "getfreq.h" -#include "getcore.h" -#include "getgov.h" -#include "trayfreq_set_interface.h" -#include "bat_tray.h" -#include "defaults.h" - -#include <gtk/gtk.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <libintl.h> - - -void tray_set_defaults(); -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(); +void tray_set_defaults(); +void tray_init(); +void tray_set_tooltip(const char* msg); +void tray_update_icon_percent(); +void tray_show(); +void tray_hide(); +bool tray_visible(); +bool tray_embedded(); #endif @@ -18,6 +18,69 @@ #include "trayfreq.h" +//#include "widget_manager.h" +#include "tray.h" +#include "bat_tray.h" +#include "getfreq.h" +#include "getcore.h" +#include "getgov.h" +#include "config_file.h" +#include "reload.h" +#include "defaults.h" +#include "debug.h" + +#include <gtk/gtk.h> +//#include <glib.h> +#include <stdlib.h> +#include <stdio.h> +#include <libintl.h> +#include <locale.h> + +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)) + { + debug("Couldn't start gtk\n"); + g_error( _("GTK Error: gtk_init_check returned FALSE.\nBailing.") ); + return 1; + } + + struct sigaction sig_act; + sig_act.sa_handler = reload_config; + sig_act.sa_flags = 0; + sigemptyset(&sig_act.sa_mask); + + if (sigaction(SIGUSR1, &sig_act, NULL) == -1) + { + debug("WARN: Couldn't set sigaction for SIGUSR1\n"); + } + config_init(); + gc_init(); + gg_init(); + gf_init(); + tray_init(); + tray_show(); + + // Show battery tray only if we're supposed to + if(_DEFAULT_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; +} + void config_init() { struct config_file config; @@ -79,47 +142,3 @@ void config_init() config_close(&config); } -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)) - { - debug("Couldn't start gtk\n"); - g_error( _("GTK Error: gtk_init_check returned FALSE.\nBailing.") ); - return 1; - } - - struct sigaction sig_act; - sig_act.sa_handler = reload_config; - sig_act.sa_flags = 0; - sigemptyset(&sig_act.sa_mask); - - if (sigaction(SIGUSR1, &sig_act, NULL) == -1) - { - debug("WARN: Couldn't set sigaction for SIGUSR1\n"); - } - config_init(); - gc_init(); - gg_init(); - gf_init(); - tray_init(); - tray_show(); - - // Show battery tray only if we're supposed to - if(_DEFAULT_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; -} @@ -19,25 +19,6 @@ #ifndef TRAYFREQ_H #define TRAYFREQ_H -#include "widget_manager.h" -#include "tray.h" -#include "bat_tray.h" -#include "getfreq.h" -#include "getcore.h" -#include "getgov.h" -#include "config_file.h" -#include "reload.h" -#include "defaults.h" -#include "debug.h" - -#include <gtk/gtk.h> -#include <glib.h> -#include <stdlib.h> -#include <stdio.h> -#include <libintl.h> -#include <locale.h> - void config_init(); -//int main(int argc, char** argv); #endif diff --git a/trayfreq_set_interface.c b/trayfreq_set_interface.c index e64a88e..fc847e6 100644 --- a/trayfreq_set_interface.c +++ b/trayfreq_set_interface.c @@ -19,7 +19,7 @@ #include "trayfreq_set_interface.h" #include "debug.h" - +#include "defaults.h" #include <stdio.h> #include <stdlib.h> diff --git a/trayfreq_set_interface.h b/trayfreq_set_interface.h index bdc13a3..bdbf652 100644 --- a/trayfreq_set_interface.h +++ b/trayfreq_set_interface.h @@ -19,8 +19,6 @@ #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); diff --git a/widget_manager.c b/widget_manager.c deleted file mode 100644 index 30669a6..0000000 --- a/widget_manager.c +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************ - * 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 * - * <http://www.gnu.org/licenses/>. * - ************************************************************************/ - -#include "widget_manager.h" - -GList* wm_widgets; - -void wm_add_widget(GtkWidget* widget) -{ - wm_widgets = g_list_prepend(wm_widgets, widget); -} - -void wm_show_widgets() -{ - GList* curr = g_list_last(wm_widgets); - while(curr) - { - gtk_widget_show(curr->data); - curr = g_list_previous(curr); - } -} diff --git a/widget_manager.h b/widget_manager.h deleted file mode 100644 index d6c2d10..0000000 --- a/widget_manager.h +++ /dev/null @@ -1,30 +0,0 @@ -/************************************************************************ - * 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 * - * <http://www.gnu.org/licenses/>. * - ************************************************************************/ - -#ifndef WIDGET_MANAGER_H -#define WIDGET_MANAGER_H - -#include <gtk/gtk.h> -#include <glib.h> - -/* The Widget Manager will be a list of widgets. The list will be traversed from the tail to the head. */ - -void wm_add_widget(GtkWidget* widget); -void wm_show_widgets(); - -#endif |