From df3ee03d3814ba51e0d09f90f419a5f9650e2105 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 28 Mar 2014 23:41:51 +1300 Subject: A night full of rewriting and tidying --- AUTHORS | 6 - src/Makefile | 27 ++-- src/bat_tray.c | 126 ------------------- src/bat_tray.h | 29 ----- src/bat_tray/bat_tray.c | 193 +++++++++++++++++++++++++++++ src/bat_tray/bat_tray.h | 40 ++++++ src/bat_tray/getbat.c | 30 +++++ src/bat_tray/getbat.h | 26 ++++ src/common.c | 86 +++++++++++++ src/common.h | 28 +++++ src/config.h.in | 61 --------- src/config_file.c | 15 +-- src/config_file.h | 17 +-- src/defaults.c | 75 ++--------- src/defaults.h | 32 +++-- src/freq_tray/getcore.c | 50 ++++++++ src/freq_tray/getcore.h | 25 ++++ src/freq_tray/getfreq.c | 129 +++++++++++++++++++ src/freq_tray/getfreq.h | 31 +++++ src/freq_tray/getgov.c | 108 ++++++++++++++++ src/freq_tray/getgov.h | 28 +++++ src/getbat.c | 199 ------------------------------ src/getbat.h | 37 ------ src/getcore.c | 49 -------- src/getcore.h | 24 ---- src/getfreq.c | 128 ------------------- src/getfreq.h | 30 ----- src/getgov.c | 107 ---------------- src/getgov.h | 27 ---- src/tray.c | 76 ++++++------ src/tray.h | 15 +-- src/trayfreq.c | 69 ++++++----- src/trayfreq_set.c | 120 ------------------ src/trayfreq_set/trayfreq_set.c | 121 ++++++++++++++++++ src/trayfreq_set/trayfreq_set_interface.c | 46 +++++++ src/trayfreq_set/trayfreq_set_interface.h | 25 ++++ src/trayfreq_set_interface.c | 45 ------- src/trayfreq_set_interface.h | 24 ---- src/utilities.c | 37 ------ src/utilities.h | 30 ----- src/widget_manager.c | 15 +-- src/widget_manager.h | 15 +-- 42 files changed, 1125 insertions(+), 1276 deletions(-) delete mode 100644 AUTHORS delete mode 100644 src/bat_tray.c delete mode 100644 src/bat_tray.h create mode 100644 src/bat_tray/bat_tray.c create mode 100644 src/bat_tray/bat_tray.h create mode 100644 src/bat_tray/getbat.c create mode 100644 src/bat_tray/getbat.h create mode 100644 src/common.c create mode 100644 src/common.h delete mode 100644 src/config.h.in create mode 100644 src/freq_tray/getcore.c create mode 100644 src/freq_tray/getcore.h create mode 100644 src/freq_tray/getfreq.c create mode 100644 src/freq_tray/getfreq.h create mode 100644 src/freq_tray/getgov.c create mode 100644 src/freq_tray/getgov.h delete mode 100644 src/getbat.c delete mode 100644 src/getbat.h delete mode 100644 src/getcore.c delete mode 100644 src/getcore.h delete mode 100644 src/getfreq.c delete mode 100644 src/getfreq.h delete mode 100644 src/getgov.c delete mode 100644 src/getgov.h delete mode 100644 src/trayfreq_set.c create mode 100644 src/trayfreq_set/trayfreq_set.c create mode 100644 src/trayfreq_set/trayfreq_set_interface.c create mode 100644 src/trayfreq_set/trayfreq_set_interface.h delete mode 100644 src/trayfreq_set_interface.c delete mode 100644 src/trayfreq_set_interface.h delete mode 100644 src/utilities.c delete mode 100644 src/utilities.h diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index 64e8b86..0000000 --- a/AUTHORS +++ /dev/null @@ -1,6 +0,0 @@ -Original Trayfreq (http://trayfreq.sourceforge.net/): -Devin Smittle -Shae Smittle - -Trayfreq for Archlinux w/kernel > 3.0.4: -David Phillips diff --git a/src/Makefile b/src/Makefile index 8dd15a9..284321f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,4 @@ CC = gcc -DEFS = -DHAVE_CONFIG_H GLIB_CFLAGS = -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include GLIB_LIBS = -lglib-2.0 @@ -10,12 +9,20 @@ GTK_CFLAGS = -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pa #GTK_LIBS = -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype GTK_LIBS = -lgtk-x11-2.0 -lgobject-2.0 -PACKAGE_VERSION = 0.2 -VERSION = 0.2 - - -trayfreq_SOURCES = getcore.c getcore.h getfreq.c getfreq.h getgov.c getgov.h tray.c tray.h trayfreq.c utilities.c utilities.h widget_manager.c widget_manager.h trayfreq_set_interface.c trayfreq_set_interface.h config_file.c config_file.h defaults.c defaults.h getbat.c getbat.h bat_tray.c bat_tray.h -#trayfreq_SOURCES = getcore.c getcore.h getfreq.c getfreq.h getgov.c getgov.h tray.c tray.h trayfreq.c utilities.c utilities.h widget_manager.c widget_manager.h config_file.c config_file.h defaults.c defaults.h getbat.c getbat.h bat_tray.c bat_tray.h +#PACKAGE_VERSION = 0.3 +#VERSION = 0.3 + +trayfreq_SOURCES = freq_tray/getcore.c \ + freq_tray/getfreq.c \ + freq_tray/getgov.c \ + tray.c \ + trayfreq.c \ + widget_manager.c \ + trayfreq_set/trayfreq_set_interface.c \ + config_file.c \ + defaults.c \ + bat_tray/bat_tray.c \ + common.c trayfreq_CFLAGS = $(GTK_CFLAGS) $(GLIB_CFLAGS) -Wall @@ -24,7 +31,9 @@ trayfreq_LDFLAGS = $(GTK_LIBS) $(GLIB_LIBS) -lm trayfreq_set_CFLAGS = $(GTK_CFLAGS) $(GLIB_CFLAGS) -Wall trayfreq_set_LDFLAGS = $(GTK_LIBS) $(GLIB_LIBS) -lm -trayfreq_set_SOURCES = trayfreq_set.c getfreq.c getcore.c +trayfreq_set_SOURCES = trayfreq_set/trayfreq_set.c \ + freq_tray/getfreq.c \ + freq_tray/getcore.c all: trayfreq trayfreq-set @@ -36,4 +45,4 @@ trayfreq: $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) clean: - rm trayfreq trayfreq-set + rm -f trayfreq trayfreq-set diff --git a/src/bat_tray.c b/src/bat_tray.c deleted file mode 100644 index c4b7d61..0000000 --- a/src/bat_tray.c +++ /dev/null @@ -1,126 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq. * - * * - * trayfreq 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 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. If not, see . * - ************************************************************************/ - -#include "bat_tray.h" -#include "getbat.h" -#include "utilities.h" - -#include -#include -#include -#include - -static GtkStatusIcon* tray; -#define TOOLTIP_TEXT_SIZE 500 -gchar tooltip_text[TOOLTIP_TEXT_SIZE]; - -void bat_tray_set_tooltip(const gchar* msg) -{ - memset(tooltip_text, '\0', TOOLTIP_TEXT_SIZE); - memmove(tooltip_text, msg, strlen(msg)); -} - -static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean keyboard_mode,GtkTooltip* tooltip,gpointer data) -{ - gchar msg[500]; - memset(msg, '\0', 500); - - //printf("dis: %i, char: %i, full: %i\n", gb_discharging(), gb_charging(), gb_charged()); - - if(gb_discharging()) - { - //gchar time[50]; - //memset(time, '\0', 50); - sprintf(msg, "Discharging (%i%% left)", gb_percent()); - } else if(gb_charging()) { - //gchar time[50]; - //memset(time, '\0', 50); - sprintf(msg, "Charging (%i%%)", gb_percent()); - } else if(gb_charged()) { - sprintf(msg, "Fully Charged\nAC Plugged In"); - } else { - sprintf(msg, "Unknown Status"); - } - - bat_tray_set_tooltip(msg); - gtk_tooltip_set_text(tooltip, tooltip_text); - - return TRUE; -} - -void bat_tray_update_icon_percent() -{ - gchar* file; - int percent = gb_percent(); - int adjusted_percent; - gchar adjusted_percent_string[4]; - memset(adjusted_percent_string, '\0', 4); - - if(percent > 90) - adjusted_percent=100; - else if(percent > 70) - adjusted_percent=80; - else if(percent > 50) - adjusted_percent=60; - else if(percent > 30) - adjusted_percent=40; - else if(percent > 10) - adjusted_percent=20; - else - adjusted_percent=0; - - sprintf(adjusted_percent_string, "%i", adjusted_percent); - - if(gb_discharging()) - { - file = g_strconcat(util_get_prefix(), "/share/trayfreq/traybat-", adjusted_percent_string, ".png", NULL); - } else if(gb_charging()) - { - file = g_strconcat(util_get_prefix(), "/share/trayfreq/traybat-", adjusted_percent_string, "-charging.png", NULL); - } else { - file = g_strconcat(util_get_prefix(), "/share/trayfreq/traybat-charged.png", NULL); - } - - gtk_status_icon_set_from_file(tray, file); -} - -static gboolean update_icon(gpointer user_data) -{ - bat_tray_update_icon_percent(); - return TRUE; -} - -void bat_tray_init() -{ - tray = gtk_status_icon_new(); - gchar* icon_file = g_strconcat(util_get_prefix(), "/share/trayfreq/traybat-charged.png", NULL); - 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); -} - - -void bat_tray_show() -{ - gtk_status_icon_set_visible(tray, TRUE); -} - -void bat_tray_hide() -{ - gtk_status_icon_set_visible(tray, FALSE); -} \ No newline at end of file diff --git a/src/bat_tray.h b/src/bat_tray.h deleted file mode 100644 index a4a57c1..0000000 --- a/src/bat_tray.h +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq. * - * * - * trayfreq 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 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. If not, see . * - ************************************************************************/ - -#ifndef BAT_TRAY_H -#define BAT_TRAY_H 1 - -#include - -void bat_tray_set_tooltip(const gchar* msg); -void bat_tray_update_icon_percent(); -void bat_tray_init(); -void bat_tray_show(); -void bat_tray_hide(); - -#endif \ No newline at end of file diff --git a/src/bat_tray/bat_tray.c b/src/bat_tray/bat_tray.c new file mode 100644 index 0000000..0cfb415 --- /dev/null +++ b/src/bat_tray/bat_tray.c @@ -0,0 +1,193 @@ +/************************************************************************ + * 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 * + * . * + ************************************************************************/ + +#include "bat_tray.h" +#include "getbat.h" +#include "../common.h" + +#include +#include +#include +#include + +static GtkStatusIcon* tray; + + +int _BAT_NUM; +char CHARGE_VALUE_PATH[512]; +char CHARGE_STATE_PATH[512]; + +/*********************************************************************** + * Return the battery level percentage + **********************************************************************/ +//#define get_bat_percent() get_int_value_from_file(CHARGE_VALUE_PATH); +int get_bat_percent(){return get_int_value_from_file(CHARGE_VALUE_PATH); } + + +#define TOOLTIP_TEXT_SIZE 128 +gchar tooltip_text[TOOLTIP_TEXT_SIZE]; + + +/*********************************************************************** + * Updates the battery tray tooltip text + **********************************************************************/ +static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean keyboard_mode,GtkTooltip* tooltip,gpointer data) +{ + gchar msg[TOOLTIP_TEXT_SIZE]; + + switch(get_battery_state()) + { + case STATE_DISCHARGING: + sprintf(msg, "Discharging (%i%% left)", get_bat_percent()); + break; + + case STATE_CHARGING: + break; + sprintf(msg, "Charging (%i%%)", get_bat_percent()); + case STATE_CHARGED: + sprintf(msg, "Fully charged"); + break; + + default: + sprintf(msg, "Warning: Unknown status"); + break; + } + + gtk_tooltip_set_text(tooltip, msg); + + return TRUE; +} + + +/*********************************************************************** + * Updates the battery tray icon based upon battery percent + **********************************************************************/ +static gboolean update_icon(gpointer user_data) +{ + gchar* icon_file; + unsigned int percent = get_bat_percent(); + unsigned int adjusted_percent; + gchar adjusted_percent_string[4]; + + if(percent > 90) + adjusted_percent=100; + else if(percent > 70) + adjusted_percent=80; + else if(percent > 50) + adjusted_percent=60; + else if(percent > 30) + adjusted_percent=40; + else if(percent > 10) + adjusted_percent=20; + else + adjusted_percent=0; + + sprintf(adjusted_percent_string, "%i", adjusted_percent); + + switch ( get_battery_state() ) + { + case STATE_DISCHARGING: + icon_file = g_strconcat("/usr/share/trayfreq/traybat-", adjusted_percent_string, ".png", NULL); + break; + case STATE_CHARGING: + icon_file = g_strconcat("/usr/share/trayfreq/traybat-", adjusted_percent_string, "-charging.png", NULL); + break; + + default: + icon_file = g_strconcat("/usr/share/trayfreq/traybat-charged.png", NULL); + break; + } + gtk_status_icon_set_from_file(tray, icon_file); + return TRUE; +} + + + + +void bat_tray_init() +{ + // Get the battery number, store it for later + _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); + + + 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); + 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); +} + + +void bat_tray_show() +{ + gtk_status_icon_set_visible(tray, TRUE); +} + +void bat_tray_hide() +{ + gtk_status_icon_set_visible(tray, FALSE); +} + + +/*********************************************************************** + * Return the battery state + **********************************************************************/ +int get_battery_state() +{ + if (file_has_line(CHARGE_STATE_PATH, "Discharging")) + return STATE_DISCHARGING; + + if (file_has_line(CHARGE_STATE_PATH, "Full")) + return STATE_CHARGED; + + if (file_has_line(CHARGE_STATE_PATH, "Charging")) + return STATE_CHARGING; + + return STATE_UNKNOWN; +} + +/*********************************************************************** + * Get the number of the first (who has more than one?) battery + * Returns -1 if no battery present + **********************************************************************/ +int get_bat_num() +{ + FILE* fd; + gchar file[40]; + unsigned int i; + for(i = 0; i < 3; i++) + { + sprintf(file, "/sys/class/power_supply/BAT%i/present", i); + + if( (fd = fopen(file, "r")) ) + { + if (fgetc(fd) == '1') + { + fclose(fd); + return i; + } + } + } + return -1; +} diff --git a/src/bat_tray/bat_tray.h b/src/bat_tray/bat_tray.h new file mode 100644 index 0000000..c20a833 --- /dev/null +++ b/src/bat_tray/bat_tray.h @@ -0,0 +1,40 @@ +/************************************************************************ + * 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 BAT_TRAY_H +#define BAT_TRAY_H 1 + +#include + + +// already defined in bat_tray.c : #define gb_percent get_int_value_from_file(CHARGE_VALUE_PATH); + +#define STATE_CHARGING 0 +#define STATE_DISCHARGING 1 +#define STATE_CHARGED 2 +#define STATE_FULL STATE_CHARGED +#define STATE_UNKNOWN 3 + +void bat_tray_init(); +void bat_tray_show(); +void bat_tray_hide(); + +int get_battery_state(); +int get_bat_num(); + +#endif /* ifndef BAT_TRAY_H */ \ No newline at end of file diff --git a/src/bat_tray/getbat.c b/src/bat_tray/getbat.c new file mode 100644 index 0000000..72408e7 --- /dev/null +++ b/src/bat_tray/getbat.c @@ -0,0 +1,30 @@ +/************************************************************************ + * 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 * + * . * + ************************************************************************/ +/* +#include "getbat.h" + +#include +#include +#include +#include + + + + +//gchar CURRENT_PATH[512]; +*/ \ No newline at end of file diff --git a/src/bat_tray/getbat.h b/src/bat_tray/getbat.h new file mode 100644 index 0000000..81c3c0f --- /dev/null +++ b/src/bat_tray/getbat.h @@ -0,0 +1,26 @@ +/************************************************************************ + * 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 GETBAT_H +#define GETBAT_H 1 + +#include + + + +#endif \ No newline at end of file diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..ae858a9 --- /dev/null +++ b/src/common.c @@ -0,0 +1,86 @@ +/************************************************************************ + * 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 * + * . * + ************************************************************************/ + +#include "common.h" + +#include +#include +#include +#include + +#define TRUE true +#define FALSE false + +/*********************************************************************** + * Gets integer value from file + **********************************************************************/ +int get_int_value_from_file(const char* filename) +{ + FILE* fd; + char buffer[512]; + int value; + + if(!(fd = fopen(filename, "r"))) + return -1; + + if (fgets(buffer, 100, fd)) + value = get_int(buffer); + + fclose(fd); + return value; +} + + +/*********************************************************************** + * Return true/false if a file has specified line or not + **********************************************************************/ +bool file_has_line(const char *filename, const char *line) +{ + FILE* fd; + char buffer[512]; + + if (!(fd = fopen(filename, "r"))) + return FALSE; + + while (fgets(buffer, sizeof(buffer), fd) != NULL) + { + if(strstr(buffer, line) != NULL) + { + fclose(fd); + return TRUE; + } + } + fclose(fd); + return FALSE; +} + + +/*********************************************************************** + * Fetches first number from a string + **********************************************************************/ +int get_int(const char* string) +{ + char numbers[] = "1234567890"; + char* first_num; + + first_num = strpbrk(string, numbers); + if(first_num) + return atoi(first_num); + + return 1; +} diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..bf59513 --- /dev/null +++ b/src/common.h @@ -0,0 +1,28 @@ +/************************************************************************ + * 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 COMMON_H +#define COMMON_H 1 + +#include + +int get_int_value_from_file(const char* filename); +bool file_has_line(const char *filename, const char *line); +int get_int(const char* string); + +#endif \ No newline at end of file diff --git a/src/config.h.in b/src/config.h.in deleted file mode 100644 index c75a3f5..0000000 --- a/src/config.h.in +++ /dev/null @@ -1,61 +0,0 @@ -/* src/config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -#undef NO_MINUS_C_MINUS_O - -/* Name of package */ -#undef PACKAGE - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the home page for this package. */ -#undef PACKAGE_URL - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* "" */ -#undef PREFIX - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Version number of package */ -#undef VERSION diff --git a/src/config_file.c b/src/config_file.c index 73ac321..5bfbe65 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -1,18 +1,19 @@ /************************************************************************ - * This file is part of trayfreq. * + * This file is part of trayfreq-archlinux. * * * - * trayfreq 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 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 is distributed in the hope that it will be useful, * + * 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. If not, see . * + * along with trayfreq-archlinux. If not, see * + * . * ************************************************************************/ #include "config_file.h" diff --git a/src/config_file.h b/src/config_file.h index d478e64..cb491d4 100644 --- a/src/config_file.h +++ b/src/config_file.h @@ -1,18 +1,19 @@ /************************************************************************ - * This file is part of trayfreq. * + * This file is part of trayfreq-archlinux. * * * - * trayfreq 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 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 is distributed in the hope that it will be useful, * + * 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. If not, see . * + * along with trayfreq-archlinux. If not, see * + * . * ************************************************************************/ #ifndef CONFIG_FILE_H @@ -30,4 +31,4 @@ 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); -#endif \ No newline at end of file +#endif /* ifndef CONFIG_FILE_H */ \ No newline at end of file diff --git a/src/defaults.c b/src/defaults.c index e409480..dc54dd4 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -1,74 +1,25 @@ /************************************************************************ - * This file is part of trayfreq. * + * This file is part of trayfreq-archlinux. * * * - * trayfreq 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 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 is distributed in the hope that it will be useful, * + * 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. If not, see . * + * along with trayfreq-archlinux. If not, see * + * . * ************************************************************************/ #include "defaults.h" -gchar* default_gov = NULL; -gchar* default_freq = NULL; -gchar* default_prog = NULL; -gchar* default_bat_gov = NULL; -gchar* default_ac_gov = NULL; - -gchar* def_get_gov() -{ - return default_gov; -} - -gchar* def_get_freq() -{ - return default_freq; -} - -gchar* def_get_prog() -{ - return default_prog; -} - -gchar* def_get_bat_gov() -{ - return default_bat_gov; -} - -gchar* def_get_ac_gov() -{ - return default_ac_gov; -} - -void def_set_gov(gchar* gov) -{ - default_gov = g_strdup(gov); -} - -void def_set_freq(gchar* freq) -{ - default_freq = g_strdup(freq); -} - -void def_set_prog(gchar* prog) -{ - default_prog = g_strdup(prog); -} - -void def_set_bat_gov(gchar* bat_gov) -{ - default_bat_gov = bat_gov; -} - -void def_set_ac_gov(gchar* ac_gov) -{ - default_ac_gov = ac_gov; -} \ No newline at end of file +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 diff --git a/src/defaults.h b/src/defaults.h index c6d1b87..c959cbb 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -1,18 +1,19 @@ /************************************************************************ - * This file is part of trayfreq. * + * This file is part of trayfreq-archlinux. * * * - * trayfreq 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 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 is distributed in the hope that it will be useful, * + * 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. If not, see . * + * along with trayfreq-archlinux. If not, see * + * . * ************************************************************************/ #ifndef DEFAULTS_H @@ -20,15 +21,10 @@ #include -gchar* def_get_gov(); -gchar* def_get_freq(); -gchar* def_get_prog(); -gchar* def_get_bat_gov(); -gchar* def_get_ac_gov(); -void def_set_gov(gchar* gov); -void def_set_freq(gchar* freq); -void def_set_prog(gchar* prog); -void def_set_bat_gov(gchar* bat_gov); -void def_set_ac_gov(gchar* ac_gov); +char* _DEFAULT_GOV; +char* _DEFAULT_FREQ; +char* _DEFAULT_PROG; +char* _DEFAULT_BAT_GOV; +char* _DEFAULT_AC_GOV; -#endif \ No newline at end of file +#endif /* ifndef DEFAULTS_H */ \ No newline at end of file diff --git a/src/freq_tray/getcore.c b/src/freq_tray/getcore.c new file mode 100644 index 0000000..a2ee3d3 --- /dev/null +++ b/src/freq_tray/getcore.c @@ -0,0 +1,50 @@ +/************************************************************************ + * 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 * + * . * + ************************************************************************/ + +#include "getcore.h" + +#include +#include +#include + +int NUMBER_OF_CORES; + +static gboolean core_exists(int core) +{ + FILE* fd; + char path[80]; + char corestr[4]; + + sprintf(corestr, "%i", core); + sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr); + + return (gboolean)(fd = fopen(path, "r")); +} + +void gc_init() +{ + NUMBER_OF_CORES = 0; + while(core_exists(++NUMBER_OF_CORES)); +} + + +/* to do */ +int gc_number() +{ + return NUMBER_OF_CORES; +} diff --git a/src/freq_tray/getcore.h b/src/freq_tray/getcore.h new file mode 100644 index 0000000..541d789 --- /dev/null +++ b/src/freq_tray/getcore.h @@ -0,0 +1,25 @@ +/************************************************************************ + * 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 GETCORE_H +#define GETCORE_H 1 + +void gc_init(); +int gc_number(); + +#endif diff --git a/src/freq_tray/getfreq.c b/src/freq_tray/getfreq.c new file mode 100644 index 0000000..5ac3948 --- /dev/null +++ b/src/freq_tray/getfreq.c @@ -0,0 +1,129 @@ +/************************************************************************ + * 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 * + * . * + ************************************************************************/ + +#include "getfreq.h" +#include "getcore.h" +#include "math.h" + +#include +#include +#include +#include + +/* [CORE][FREQUENCY NUMBER] */ +char AVAILABLE_FREQUENCIES[999][50][13]; +int NUMBER_OF_AVAILABLE_FREQUENCIES; + +void gf_init() +{ + gchar freq_string[500]; + + int i = 0; + int j = 0; + for(i = 0; i < gc_number(); ++i) + { + memset(freq_string, '\0', 500); + + // Get available governor freqs. If no governor, try next cpu + if (gf_available(i, freq_string, 500) == -1) + continue; + + /* go through every frequency in freq_string */ + j = 0; + gchar* curr = &freq_string[0]; + gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); + while(end_of_curr) + { + memset(AVAILABLE_FREQUENCIES[i][j], '\0', 13); + memmove(AVAILABLE_FREQUENCIES[i][j], curr, end_of_curr - curr); + + curr = end_of_curr+1; + end_of_curr = g_strstr_len(curr, strlen(curr), " "); + ++j; + } + } + NUMBER_OF_AVAILABLE_FREQUENCIES = j; +} + +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); + + if(!(fd = fopen(path, "r"))) + return -1; + + fgets(buff, 13, fd); + + freq = atoi(buff); + fclose(fd); + return freq; +} + +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); + + if(!(fd = fopen(path, "r"))) + return -1; + + fgets(out, size, fd); + + fclose(fd); + return 0; +} + +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)); + else + sprintf(out, "%.2d MHz", freq/1000); +} + +char* gf_freqa(int core, int index) +{ + return AVAILABLE_FREQUENCIES[core][index]; +} + +int gf_freqi(int core, int index) +{ + return atoi(gf_freqa(core, index)); +} + +int gf_number() +{ + return NUMBER_OF_AVAILABLE_FREQUENCIES; +} diff --git a/src/freq_tray/getfreq.h b/src/freq_tray/getfreq.h new file mode 100644 index 0000000..a1cbd92 --- /dev/null +++ b/src/freq_tray/getfreq.h @@ -0,0 +1,31 @@ +/************************************************************************ + * 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 GETFREQ_H +#define GETFREQ_H 1 + +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(); + + +#endif diff --git a/src/freq_tray/getgov.c b/src/freq_tray/getgov.c new file mode 100644 index 0000000..cbb571c --- /dev/null +++ b/src/freq_tray/getgov.c @@ -0,0 +1,108 @@ +/************************************************************************ + * 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 * + * . * + ************************************************************************/ + +#include "getgov.h" +#include "getcore.h" + +#include +#include +#include +#include + +/* [CORE][GOVERNOR NUMBER] */ +gchar AVAILABLE_GOVERNORS[999][50][13]; +gint NUMBER_OF_AVAILABLE_GOVERNORS; + +void gg_init() +{ + gchar gov_string[500]; + int i = 0; + int j = 0; + for(i = 0; i < gc_number(); ++i) + { + memset(gov_string, '\0', 500); + gg_available(i, gov_string, 500); + + /* 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); + + curr = end_of_curr+1; + end_of_curr = g_strstr_len(curr, strlen(curr), " "); + ++j; + } + } + NUMBER_OF_AVAILABLE_GOVERNORS = j; +} + +int gg_current(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_governor", corestr); + + if(!(fd = fopen(path, "r"))) + return -1; + + fgets(out, size, fd); + + /* remove newline at the end */ + gchar* newline = g_strrstr(out, "\n"); + *newline = '\0'; + + fclose(fd); + return 0; +} + +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); + + if(!(fd = fopen(path, "r"))) + return -1; + + fgets(out, size, fd); + + fclose(fd); + return 0; +} + +char* gg_gov(int core, int index) +{ + return AVAILABLE_GOVERNORS[core][index]; +} + +int gg_number() +{ + return NUMBER_OF_AVAILABLE_GOVERNORS; +} diff --git a/src/freq_tray/getgov.h b/src/freq_tray/getgov.h new file mode 100644 index 0000000..b4fdc29 --- /dev/null +++ b/src/freq_tray/getgov.h @@ -0,0 +1,28 @@ +/************************************************************************ + * 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 GETGOV_H +#define GETGOV_H 1 + +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(); + +#endif diff --git a/src/getbat.c b/src/getbat.c deleted file mode 100644 index ad3a760..0000000 --- a/src/getbat.c +++ /dev/null @@ -1,199 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq. * - * * - * trayfreq 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 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. If not, see . * - ************************************************************************/ - -#include "getbat.h" - -#include -#include -#include -#include - -gint BAT_NUM; -gint MAX_CAPACITY; -gint WARN_CAPACITY; -gint LOW_CAPACITY; - -//gchar INFO_PATH[30]; -gchar CHARGE_VALUE_PATH[40]; -gchar CHARGE_STATE_PATH[40]; -gchar CURRENT_PATH[40]; - -static gint get_bat_num() -{ - FILE* fd; - gchar file[40]; - gint i; - for(i = 0; i < 3; i++) - { - memset(file, '\0', 40); - sprintf(file, "/sys/class/power_supply/BAT%i/present", i); - - if((fd = fopen(file, "r")) != NULL) - { - if (fgetc(fd) == '1') - { - fclose(fd); - return i; - } - } - } - return -1; -} - -static gint get_int(char* line) -{ - char numbers[] = "1234567890"; - char* first_num; - - first_num = strpbrk (line, numbers); - if(first_num) - return atoi(first_num); - return 1; -} - -static gint get_int_value_from_file(const gchar* path) -{ - FILE* fd; - gchar buff[100]; - gint value; - - if(!(fd = fopen(path, "r"))) - return -1; - - if (fgets(buff, 100, fd)) - value = get_int(buff); - - fclose(fd); - return value; -} - -static gboolean file_has_line(const gchar* path, const gchar* line) -{ - FILE* fd; - gchar buff[100]; - - if(!(fd = fopen(path, "r"))) - return FALSE; - - while(fgets(buff, 100, fd) != NULL) - { - if(strstr(buff, line) != NULL) - { - fclose(fd); - return TRUE; - } - } - fclose(fd); - return FALSE; -} - -gboolean gb_init() -{ - BAT_NUM = get_bat_num(); - //sprintf(INFO_PATH, "/proc/acpi/battery/BAT%i/info", gb_number()); - sprintf(CHARGE_VALUE_PATH, "/sys/class/power_supply/BAT%i/capacity", gb_number()); - sprintf(CHARGE_STATE_PATH, "/sys/class/power_supply/BAT%i/status", gb_number()); - sprintf(CURRENT_PATH, "/sys/class/power_supply/BAT%i/charge_now", gb_number()); - - FILE* fd; - gchar buff[100]; - - /*if(!(fd = fopen(INFO_PATH, "r"))) - return FALSE; - - while(fgets(buff, 100, fd)!= NULL) - { - if(strncmp("last full capacity:", buff, 19) == 0) - MAX_CAPACITY = get_int(buff); - else if(strncmp("design capacity warning:", buff, 24) == 0) - WARN_CAPACITY = get_int(buff); - else if(strncmp("design capacity low:", buff, 20) == 0) - LOW_CAPACITY = get_int(buff); - else if(strncmp("present: no",buff, 27) == 0) - return FALSE; - } - fclose(fd);*/ - return TRUE; -} - -gint gb_current_rate() -{ - return get_int_value_from_file(CURRENT_PATH); - return 0; -} - -gboolean gb_discharging() -{ - return file_has_line(CHARGE_STATE_PATH, "Discharging"); -} - -gboolean gb_charged() -{ - return file_has_line(CHARGE_STATE_PATH, "Full"); -} - -gboolean gb_charging() -{ - return file_has_line(CHARGE_STATE_PATH, "Charging"); -} - -gint gb_number() -{ - return BAT_NUM; -} -/* -gint gb_max_capacity() -{ - return MAX_CAPACITY; -} - -gint gb_warn_capacity() -{ - return WARN_CAPACITY; -} - -gint gb_low_capacity() -{ - return LOW_CAPACITY; -}*/ - -gint gb_percent() -{ - return get_int_value_from_file(CHARGE_VALUE_PATH); -} -/* -void gb_time(gchar* time) -{ - float minutes = (float)gb_current_rate()/1000; - - //float minutes = ftime/60; - - //if(minutes < 10) - sprintf(time, "%i", (int)minutes); - //else - // sprintf(time, "%i:%i", (int)ftime, (int)minutes); -} - -void gb_charge_time(gchar* time) -{ - float ftime = ((float)gb_max_capacity() - (float)gb_percent()) / (float)gb_current_rate(); - float minutes = ((float)ftime - (int)ftime) * (float)60; - if(minutes < 10) - sprintf(time, "%i:0%i", (int)ftime, (int)minutes); - else - sprintf(time, "%i:%i", (int)ftime, (int)minutes); -}*/ \ No newline at end of file diff --git a/src/getbat.h b/src/getbat.h deleted file mode 100644 index 6dcc3c9..0000000 --- a/src/getbat.h +++ /dev/null @@ -1,37 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq. * - * * - * trayfreq 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 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. If not, see . * - ************************************************************************/ - -#ifndef GETBAT_H -#define GETBAT_H 1 - -#include - -gboolean gb_init(); -gint gb_current_capacity(); -gint gb_current_rate(); -gboolean gb_discharging(); -gboolean gb_charged(); -gboolean gb_charging(); -gint gb_number(); -//gint gb_max_capacity(); -//gint gb_warn_capacity(); -//gint gb_low_capacity(); -gint gb_percent(); -//void gb_time(gchar* time); -//void gb_charge_time(gchar* time); - -#endif \ No newline at end of file diff --git a/src/getcore.c b/src/getcore.c deleted file mode 100644 index 617507c..0000000 --- a/src/getcore.c +++ /dev/null @@ -1,49 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq. * - * * - * trayfreq 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 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. If not, see . * - ************************************************************************/ - -#include "getcore.h" - -#include -#include -#include - -int NUMBER_OF_CORES; - -static gboolean core_exists(int core) -{ - FILE* fd; - char path[80]; - char corestr[4]; - - sprintf(corestr, "%i", core); - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr); - - return (gboolean)(fd = fopen(path, "r")); -} - -void gc_init() -{ - NUMBER_OF_CORES = 0; - while(core_exists(++NUMBER_OF_CORES)); -} - - -/* to do */ -int gc_number() -{ - return NUMBER_OF_CORES; -} diff --git a/src/getcore.h b/src/getcore.h deleted file mode 100644 index ae4852f..0000000 --- a/src/getcore.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq. * - * * - * trayfreq 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 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. If not, see . * - ************************************************************************/ - -#ifndef GETCORE_H -#define GETCORE_H 1 - -void gc_init(); -int gc_number(); - -#endif diff --git a/src/getfreq.c b/src/getfreq.c deleted file mode 100644 index 3195166..0000000 --- a/src/getfreq.c +++ /dev/null @@ -1,128 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq. * - * * - * trayfreq 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 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. If not, see . * - ************************************************************************/ - -#include "getfreq.h" -#include "getcore.h" -#include "math.h" - -#include -#include -#include -#include - -/* [CORE][FREQUENCY NUMBER] */ -char AVAILABLE_FREQUENCIES[999][50][13]; -int NUMBER_OF_AVAILABLE_FREQUENCIES; - -void gf_init() -{ - gchar freq_string[500]; - - int i = 0; - int j = 0; - for(i = 0; i < gc_number(); ++i) - { - memset(freq_string, '\0', 500); - - // Get available governor freqs. If no governor, try next cpu - if (gf_available(i, freq_string, 500) == -1) - continue; - - /* go through every frequency in freq_string */ - j = 0; - gchar* curr = &freq_string[0]; - gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); - while(end_of_curr) - { - m