aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <dbphillipsnz@gmail.com>2014-05-10 21:30:16 +1200
committerDavid <dbphillipsnz@gmail.com>2014-06-06 20:29:41 +1200
commit75c186f2e6ad9dd37027f19bdb263daa83045e4b (patch)
treeeb49709830c10a67d8e39a9ac83f97a833ff37b5
parent8e6c8cd0ad292386f1de8b22a9db060c11e5bbe6 (diff)
downloadparamano-75c186f2e6ad9dd37027f19bdb263daa83045e4b.tar.xz
Header/includes tidy-up
-rw-r--r--Makefile4
-rw-r--r--bat_tray.c6
-rw-r--r--bat_tray.h4
-rw-r--r--common.c6
-rw-r--r--common.h5
-rw-r--r--config_file.c1
-rw-r--r--config_file.h1
-rw-r--r--defaults.h4
-rw-r--r--getcore.c2
-rw-r--r--getfreq.c9
-rw-r--r--reload.c6
-rw-r--r--reload.h4
-rw-r--r--tray.c42
-rw-r--r--tray.h33
-rw-r--r--trayfreq.c107
-rw-r--r--trayfreq.h19
-rw-r--r--trayfreq_set_interface.c2
-rw-r--r--trayfreq_set_interface.h2
-rw-r--r--widget_manager.c36
-rw-r--r--widget_manager.h30
20 files changed, 124 insertions, 199 deletions
diff --git a/Makefile b/Makefile
index 0e49f28..78c485e 100644
--- a/Makefile
+++ b/Makefile
@@ -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 \
diff --git a/bat_tray.c b/bat_tray.c
index 2f6c7d3..8d0109d 100644
--- a/bat_tray.c
+++ b/bat_tray.c
@@ -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;
diff --git a/bat_tray.h b/bat_tray.h
index 583de57..e459a11 100644
--- a/bat_tray.h
+++ b/bat_tray.h
@@ -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
diff --git a/common.c b/common.c
index c0e44ef..5ffdd8b 100644
--- a/common.c
+++ b/common.c
@@ -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
**********************************************************************/
diff --git a/common.h b/common.h
index 9eb7716..dfec86b 100644
--- a/common.h
+++ b/common.h
@@ -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
diff --git a/defaults.h b/defaults.h
index f79fc9a..ed6fabd 100644
--- a/defaults.h
+++ b/defaults.h
@@ -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;
diff --git a/getcore.c b/getcore.c
index ad4878f..fc92e4c 100644
--- a/getcore.c
+++ b/getcore.c
@@ -43,8 +43,6 @@ void gc_init()
debug("Found %d cores\n",NUMBER_OF_CORES);
}
-
-/* to do */
int gc_number()
{
return NUMBER_OF_CORES;
diff --git a/getfreq.c b/getfreq.c
index 4b00775..8984ecb 100644
--- a/getfreq.c
+++ b/getfreq.c
@@ -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);
diff --git a/reload.c b/reload.c
index 6b78dac..16ee29a 100644
--- a/reload.c
+++ b/reload.c
@@ -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()
{
diff --git a/reload.h b/reload.h
index f3b974a..b0e0c4d 100644
--- a/reload.h
+++ b/reload.h
@@ -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
diff --git a/tray.c b/tray.c
index ecfc7ec..aa96fda 100644
--- a/tray.c
+++ b/tray.c
@@ -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);
}
diff --git a/tray.h b/tray.h
index b528ad6..0cbfb38 100644
--- a/tray.h
+++ b/tray.h
@@ -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
diff --git a/trayfreq.c b/trayfreq.c
index 173f54f..15c1cf6 100644
--- a/trayfreq.c
+++ b/trayfreq.c
@@ -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;
-}
diff --git a/trayfreq.h b/trayfreq.h
index f64ecf4..af1c8b0 100644
--- a/trayfreq.h
+++ b/trayfreq.h
@@ -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