From c537b4cc6d0bf2cedcb95848328e902c5be50ace Mon Sep 17 00:00:00 2001 From: David Date: Sat, 10 May 2014 13:31:43 +1200 Subject: Better makefile (I got sidetracked) --- Makefile | 62 ++++++++-- bat_tray.c | 216 +++++++++++++++++++++++++++++++++ bat_tray.h | 38 ++++++ bat_tray/bat_tray.c | 217 ---------------------------------- bat_tray/bat_tray.h | 37 ------ defaults.c | 1 + defaults.h | 1 + freq_tray/getcore.c | 51 -------- freq_tray/getcore.h | 27 ----- freq_tray/getfreq.c | 137 --------------------- freq_tray/getfreq.h | 31 ----- freq_tray/getgov.c | 113 ------------------ freq_tray/getgov.h | 28 ----- getcore.c | 51 ++++++++ getcore.h | 27 +++++ getfreq.c | 137 +++++++++++++++++++++ getfreq.h | 31 +++++ getgov.c | 113 ++++++++++++++++++ getgov.h | 28 +++++ reload.c | 11 +- reload.h | 6 + tray.h | 10 +- trayfreq.c | 36 +++--- trayfreq.h | 43 +++++++ trayfreq_set.c | 163 +++++++++++++++++++++++++ trayfreq_set/trayfreq_set.c | 163 ------------------------- trayfreq_set/trayfreq_set_interface.c | 46 ------- trayfreq_set/trayfreq_set_interface.h | 27 ----- trayfreq_set_interface.c | 46 +++++++ trayfreq_set_interface.h | 27 +++++ 30 files changed, 1008 insertions(+), 916 deletions(-) create mode 100644 bat_tray.c create mode 100644 bat_tray.h delete mode 100644 bat_tray/bat_tray.c delete mode 100644 bat_tray/bat_tray.h delete mode 100644 freq_tray/getcore.c delete mode 100644 freq_tray/getcore.h delete mode 100644 freq_tray/getfreq.c delete mode 100644 freq_tray/getfreq.h delete mode 100644 freq_tray/getgov.c delete mode 100644 freq_tray/getgov.h create mode 100644 getcore.c create mode 100644 getcore.h create mode 100644 getfreq.c create mode 100644 getfreq.h create mode 100644 getgov.c create mode 100644 getgov.h create mode 100644 trayfreq.h create mode 100644 trayfreq_set.c delete mode 100644 trayfreq_set/trayfreq_set.c delete mode 100644 trayfreq_set/trayfreq_set_interface.c delete mode 100644 trayfreq_set/trayfreq_set_interface.h create mode 100644 trayfreq_set_interface.c create mode 100644 trayfreq_set_interface.h diff --git a/Makefile b/Makefile index 3f7d098..0e49f28 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,24 @@ INSTALL_PATH=/ ifdef DEBUG EXTRA_CFLAGS+=-DDEBUG -else - EXTRA_CFLAGS= endif +DEPS = bat_tray.h \ + bool.h \ + common.h \ + config_file.h \ + debug.h \ + defaults.h \ + getcore.h \ + getfreq.h \ + getgov.h \ + reload.h \ + trayfreq.h \ + tray.h \ + trayfreq_set_interface.h \ + widget_manager.h + GLIB_CFLAGS = -I/usr/include/glib-2.0 \ -I/usr/lib/glib-2.0/include @@ -56,19 +69,41 @@ 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) $(EXTRA_CFLAGS) +# Make main trayfreq system tray program +trayfreq: bat_tray.o \ + common.o \ + config_file.o \ + defaults.o \ + getcore.o \ + getfreq.o \ + getgov.o \ + reload.o \ + trayfreq.o \ + tray.o \ + trayfreq_set_interface.o \ + widget_manager.o + $(CC) -o $@ $? $(trayfreq_LDFLAGS) + +######################################################################## +# Make trayfreq-set utility +trayfreq-set: \ + trayfreq_set.o \ + getcore.o \ + getfreq.o \ + getgov.o + + $(CC) -o $@ $? $(trayfreq_set_LDFLAGS) ######################################################################## + ######################################################################## -# Make main trayfreq system tray program -trayfreq: - $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) $(EXTRA_CFLAGS) +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(trayfreq_CFLAGS) $(EXTRA_CFLAGS) ######################################################################## + ######################################################################## # Make language files lang: @@ -79,7 +114,7 @@ lang: ######################################################################## # Remove generated files clean: - rm -f trayfreq trayfreq-set lc/*.mo + rm -f trayfreq trayfreq-set *.o lang/*.mo ######################################################################## @@ -87,14 +122,17 @@ clean: # Install entire suite install: mkdir -p $(INSTALL_PATH)/usr/share/trayfreq/ - cp data/*.png $(INSTALL_PATH)/usr/share/trayfreq/ - mkdir -p $(INSTALL_PATH)/usr/share/locale/fr/LC_MESSAGES/ + mkdir -p $(INSTALL_PATH)/etc/ + + cp data/*.png $(INSTALL_PATH)/usr/share/trayfreq/ cp lc/fr.mo $(INSTALL_PATH)/usr/share/locale/fr/LC_MESSAGES/trayfreq.mo - install -Dm 644 data/trayfreq.conf $(INSTALL_PATH)/usr/share/trayfreq/trayfreq.conf + install -Dm 644 data/trayfreq.conf $(INSTALL_PATH)/etc/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 + ln -s /usr/share/licenses/common/GLPv3/license.txt $(INSTALL_PATH)/usr/share/trayfreq/LICENCE + ln -s ../../../etc/trayfreq.conf $(INSTALL_PATH)/usr/share/trayfreq/trayfreq.conf ######################################################################## diff --git a/bat_tray.c b/bat_tray.c new file mode 100644 index 0000000..2f6c7d3 --- /dev/null +++ b/bat_tray.c @@ -0,0 +1,216 @@ +/************************************************************************ + * 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 +#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]; + //memset(msg,0,TOOLTIP_TEXT_SIZE); + switch(get_battery_state()) + { + case STATE_DISCHARGING: + debug("Discharging\n"); + sprintf(msg, _("Discharging (%d%%)"), get_bat_percent()); + break; + + case STATE_CHARGING: + 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; +} + + +/*********************************************************************** + * 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]; + + + // TO DO: do this with rounding and divisio etc + 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; + + debug("Rounded/adjusted percentage: %d\n",adjusted_percent); + sprintf(adjusted_percent_string, "%d", 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; + } + + debug("Setting tray icon to '%s'\n",icon_file); + 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%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); + gtk_status_icon_set_has_tooltip (tray, TRUE); + g_signal_connect(G_OBJECT(tray), "query-tooltip", GTK_SIGNAL_FUNC(update_tooltip), NULL); + g_timeout_add(5000, update_icon, NULL); +} + + +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); +} + + +/*********************************************************************** + * Return the battery state + **********************************************************************/ +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")) + { + debug("Battery charging\n"); + return STATE_CHARGING; + } + debug("Fallthrough: unknown status\n"); + 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%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.h b/bat_tray.h new file mode 100644 index 0000000..583de57 --- /dev/null +++ b/bat_tray.h @@ -0,0 +1,38 @@ +/************************************************************************ + * 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 + +#include +#include "debug.h" +#include "common.h" + +#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 */ diff --git a/bat_tray/bat_tray.c b/bat_tray/bat_tray.c deleted file mode 100644 index 0037ce4..0000000 --- a/bat_tray/bat_tray.c +++ /dev/null @@ -1,217 +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 * - * . * - ************************************************************************/ - - -#include "bat_tray.h" -#include "../common.h" - -#include -#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]; - //memset(msg,0,TOOLTIP_TEXT_SIZE); - switch(get_battery_state()) - { - case STATE_DISCHARGING: - debug("Discharging\n"); - sprintf(msg, _("Discharging (%d%%)"), get_bat_percent()); - break; - - case STATE_CHARGING: - 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; -} - - -/*********************************************************************** - * 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]; - - - // TO DO: do this with rounding and divisio etc - 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; - - debug("Rounded/adjusted percentage: %d\n",adjusted_percent); - sprintf(adjusted_percent_string, "%d", 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; - } - - debug("Setting tray icon to '%s'\n",icon_file); - 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%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); - gtk_status_icon_set_has_tooltip (tray, TRUE); - g_signal_connect(G_OBJECT(tray), "query-tooltip", GTK_SIGNAL_FUNC(update_tooltip), NULL); - g_timeout_add(5000, update_icon, NULL); -} - - -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); -} - - -/*********************************************************************** - * Return the battery state - **********************************************************************/ -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")) - { - debug("Battery charging\n"); - return STATE_CHARGING; - } - debug("Fallthrough: unknown status\n"); - 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%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 deleted file mode 100644 index 1d4c993..0000000 --- a/bat_tray/bat_tray.h +++ /dev/null @@ -1,37 +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 * - * . * - ************************************************************************/ - -#ifndef BAT_TRAY_H -#define BAT_TRAY_H - -#include -#include "../debug.h" - -#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 */ diff --git a/defaults.c b/defaults.c index 6b605fc..1e59095 100644 --- a/defaults.c +++ b/defaults.c @@ -23,4 +23,5 @@ char* _DEFAULT_FREQ; char* _DEFAULT_PROG; char* _DEFAULT_BAT_GOV; char* _DEFAULT_AC_GOV; +bool _DEFAULT_SHOW_BATTERY = TRUE; bool _DEFAULT_USE_SUDO = FALSE; diff --git a/defaults.h b/defaults.h index f1d4202..d1565d2 100644 --- a/defaults.h +++ b/defaults.h @@ -26,6 +26,7 @@ char* _DEFAULT_FREQ; char* _DEFAULT_PROG; char* _DEFAULT_BAT_GOV; char* _DEFAULT_AC_GOV; +bool _DEFAULT_SHOW_BATTERY; bool _DEFAULT_USE_SUDO; #endif /* ifndef DEFAULTS_H */ diff --git a/freq_tray/getcore.c b/freq_tray/getcore.c deleted file mode 100644 index ad4878f..0000000 --- a/freq_tray/getcore.c +++ /dev/null @@ -1,51 +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 * - * . * - ************************************************************************/ - -#include "getcore.h" - -#include -#include -#include - -unsigned int NUMBER_OF_CORES; - -static gboolean core_exists(unsigned int core) -{ - FILE* fd; - char path[80]; - char corestr[4]; - - 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'\n",core,path); - return (gboolean)(fd = fopen(path, "r")); -} - -void gc_init() -{ - NUMBER_OF_CORES = 0; - while(core_exists(++NUMBER_OF_CORES)); - debug("Found %d cores\n",NUMBER_OF_CORES); -} - - -/* to do */ -int gc_number() -{ - return NUMBER_OF_CORES; -} diff --git a/freq_tray/getcore.h b/freq_tray/getcore.h deleted file mode 100644 index 43dcd12..0000000 --- a/freq_tray/getcore.h +++ /dev/null @@ -1,27 +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 * - * . * - ************************************************************************/ - -#ifndef GETCORE_H -#define GETCORE_H - -#include "../debug.h" - -void gc_init(); -int gc_number(); - -#endif diff --git a/freq_tray/getfreq.c b/freq_tray/getfreq.c deleted file mode 100644 index 4b00775..0000000 --- a/freq_tray/getfreq.c +++ /dev/null @@ -1,137 +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 * - * . * - ************************************************************************/ - -#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() -{ - // 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); - - // 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; - 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; - debug("Found %d frequencies\n",j); -} - -int gf_current(int core) -{ - FILE* fd; - char buff[13]; - char path[80]; - int freq; - - sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", core); - - if(!(fd = fopen(path, "r"))) - { - 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; -} - -int gf_available(int core, char* out, int size) -{ - FILE* fd; - char path[80]; - - 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); - - 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); - - debug("Prepared freq label '%s' for freq %d\n",out,freq); -} - -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/freq_tray/getfreq.h b/freq_tray/getfreq.h deleted file mode 100644 index 8df9eca..0000000 --- a/freq_tray/getfreq.h +++ /dev/null @@ -1,31 +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 * - * . * - ************************************************************************/ - -#ifndef GETFREQ_H -#define GETFREQ_H - -void gf_init(); -int gf_current(int core); -int gf_available(int core, char* out, int size); -void gf_get_frequency_label(int freq, char* out); -char* gf_freqa(int core, int index); -int gf_freqi(int core, int index); -int gf_number(); - - -#endif diff --git a/freq_tray/getgov.c b/freq_tray/getgov.c deleted file mode 100644 index 181ad41..0000000 --- a/freq_tray/getgov.c +++ /dev/null @@ -1,113 +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 * - * . * - ************************************************************************/ - -#include "string.h" -#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"))) - { - debug("Couldn't open '%s'\n",path); - return -1; - } - - fgets(out, size, fd); - // Chomp - gchar* newline = g_strrstr(out, "\n"); - *newline = '\0'; - - debug("Current gov for core %d is '%s'\n",core,out); - - fclose(fd); - return 0; -} - -int gg_available(int core, char* out, int size) -{ - FILE* fd; - char path[80]; - - 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); - - 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/freq_tray/getgov.h b/freq_tray/getgov.h deleted file mode 100644 index fca341d..0000000 --- a/freq_tray/getgov.h +++ /dev/null @@ -1,28 +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 * - * . * - ************************************************************************/ - -#ifndef GETGOV_H -#define GETGOV_H - -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/getcore.c b/getcore.c new file mode 100644 index 0000000..ad4878f --- /dev/null +++ b/getcore.c @@ -0,0 +1,51 @@ +/************************************************************************ + * 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 + +unsigned int NUMBER_OF_CORES; + +static gboolean core_exists(unsigned int core) +{ + FILE* fd; + char path[80]; + char corestr[4]; + + 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'\n",core,path); + return (gboolean)(fd = fopen(path, "r")); +} + +void gc_init() +{ + NUMBER_OF_CORES = 0; + while(core_exists(++NUMBER_OF_CORES)); + debug("Found %d cores\n",NUMBER_OF_CORES); +} + + +/* to do */ +int gc_number() +{ + return NUMBER_OF_CORES; +} diff --git a/getcore.h b/getcore.h new file mode 100644 index 0000000..67d2f41 --- /dev/null +++ b/getcore.h @@ -0,0 +1,27 @@ +/************************************************************************ + * 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 + +#include "debug.h" + +void gc_init(); +int gc_number(); + +#endif diff --git a/getfreq.c b/getfreq.c new file mode 100644 index 0000000..4b00775 --- /dev/null +++ b/getfreq.c @@ -0,0 +1,137 @@ +/************************************************************************ + * 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() +{ + // 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); + + // 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; + 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; + debug("Found %d frequencies\n",j); +} + +int gf_current(int core) +{ + FILE* fd; + char buff[13]; + char path[80]; + int freq; + + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", core); + + if(!(fd = fopen(path, "r"))) + { + 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; +} + +int gf_available(int core, char* out, int size) +{ + FILE* fd; + char path[80]; + + 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); + + 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); + + debug("Prepared freq label '%s' for freq %d\n",out,freq); +} + +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/getfreq.h b/getfreq.h new file mode 100644 index 0000000..8df9eca --- /dev/null +++ b/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 + +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/getgov.c b/getgov.c new file mode 100644 index 0000000..181ad41 --- /dev/null +++ b/getgov.c @@ -0,0 +1,113 @@ +/************************************************************************ + * 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 "string.h" +#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"))) + { + debug("Couldn't open '%s'\n",path); + return -1; + } + + fgets(out, size, fd); + // Chomp + gchar* newline = g_strrstr(out, "\n"); + *newline = '\0'; + + debug("Current gov for core %d is '%s'\n",core,out); + + fclose(fd); + return 0; +} + +int gg_available(int core, char* out, int size) +{ + FILE* fd; + char path[80]; + + 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); + + 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/getgov.h b/getgov.h new file mode 100644 index 0000000..fca341d --- /dev/null +++ b/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 + +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/reload.c b/reload.c index fcc5ca9..2026365 100644 --- a/reload.c +++ b/reload.c @@ -16,7 +16,16 @@ * . * ************************************************************************/ +#include "reload.h" + void reload_config() { - printf("USR1\n"); + config_init(); + if (_DEFAULT_SHOW_BATTERY) + { + bat_tray_hide(); + bat_tray_show(); + } else { + bat_tray_hide(); + } } diff --git a/reload.h b/reload.h index 6ca7cf4..f3b974a 100644 --- a/reload.h +++ b/reload.h @@ -17,5 +17,11 @@ ************************************************************************/ #ifndef RELOAD_H +#define RELOAD_H +#include "trayfreq.h" +#include "defaults.h" +#include "bat_tray.h" +#include + void reload_config(); #endif diff --git a/tray.h b/tray.h index 223ac26..a9b0eed 100644 --- a/tray.h +++ b/tray.h @@ -22,11 +22,11 @@ #include #include "widget_manager.h" -#include "freq_tray/getfreq.h" -#include "freq_tray/getcore.h" -#include "freq_tray/getgov.h" -#include "trayfreq_set/trayfreq_set_interface.h" -#include "bat_tray/bat_tray.h" +#include "getfreq.h" +#include "getcore.h" +#include "getgov.h" +#include "trayfreq_set_interface.h" +#include "bat_tray.h" #include "defaults.h" #include diff --git a/trayfreq.c b/trayfreq.c index 4c23982..743bbaf 100644 --- a/trayfreq.c +++ b/trayfreq.c @@ -16,24 +16,7 @@ * . * ************************************************************************/ -#include "widget_manager.h" -#include "tray.h" -#include "bat_tray/bat_tray.h" -#include "freq_tray/getfreq.h" -#include "freq_tray/getcore.h" -#include "freq_tray/getgov.h" -#include "config_file.h" -#include "defaults.h" -#include "debug.h" - -#include -#include -#include -#include -#include -#include - -static gboolean SHOW_BATTERY = TRUE; +#include "trayfreq.h" void config_init() { @@ -76,12 +59,12 @@ void config_init() char* temp = config_get_key(&config, "battery", "show"); if (temp) - SHOW_BATTERY = ( temp[0] == '1' ); + _DEFAULT_SHOW_BATTERY = ( temp[0] == '1' ); temp = config_get_key(&config, "extra", "sudo"); if (temp) { - _DEFAULT_USE_SUDO = ( temp[0] == '1' ); + _DEFAULT_USE_SUDO = ( temp[0] == '1' ); debug("woo\n"); } @@ -105,6 +88,16 @@ int main(int argc, char** argv) 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(); @@ -113,12 +106,13 @@ int main(int argc, char** argv) tray_show(); // Show battery tray only if we're supposed to - if(SHOW_BATTERY) + 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(); diff --git a/trayfreq.h b/trayfreq.h new file mode 100644 index 0000000..f64ecf4 --- /dev/null +++ b/trayfreq.h @@ -0,0 +1,43 @@ +/************************************************************************ + * 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 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 +#include +#include +#include +#include +#include + +void config_init(); +//int main(int argc, char** argv); + +#endif diff --git a/trayfreq_set.c b/trayfreq_set.c new file mode 100644 index 0000000..785b93b --- /dev/null +++ b/trayfreq_set.c @@ -0,0 +1,163 @@ +/************************************************************************ + * 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 * + * . * + ************************************************************************/ + + +// : move a lot of this to a .h + +#include +#include +#include +#include +#include + +#include "getfreq.h" +#include "getcore.h" +#include "debug.h" + +#define FILE_PATH_STRING_SIZE 100 + +#define ARG_CORE 0x1 +#define ARG_GOV 0x2 +#define ARG_FREQ 0x4 +typedef struct { + char present; + char *core; + char *governor; + char *frequency; +} argument_summary; + +// + +char write_str_to_file(const char *file, const char *data, const char *core) +{ + FILE *fd; + char file_path[FILE_PATH_STRING_SIZE]; + + // Prepare file path + memset(file_path, '\0', sizeof(file_path)); + 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")) != NULL ) + { + debug("Writing '%s' to '%s'\n",data,file_path); + fprintf(fd, data); + fclose(fd); + return 1; + } + + // Fallthrough: File couldn't be opened for writing + fprintf(stderr, _("FAILED: Couldn't open %s for writing\n") , file_path); + return 0; +} + + +#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) + +void get_argument_summary(int argc, char **argv, argument_summary *argsum) +{ + int arg; + + // Check for -{c,g,f} xyz + for ( arg = 1; arg < argc-1; arg+=2 ) + { + // Can't have empty argument + if ( strlen(argv[arg+1]) != 0 ) + { + if ( strcmp(argv[arg], "-c") == 0 ) + { + // 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; + } + + if ( strcmp(argv[arg], "-f") == 0 ) + { + // 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; + } + + if ( strcmp(argv[arg], "-g") == 0 ) + { + // 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; + } + } + } +} + +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"); + + debug("Set gettext up\n"); + + gc_init(); + gf_init(); + + argument_summary args; + memset(&args, 0, sizeof(args)); + + // If unusual number of args, give up now + if (argc == 5) + { + get_argument_summary(argc, argv, &args); + + 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 ) ) + { + debug("Changing governor\n"); + return set_gov(args.governor , args.core); + } + + if ( args.present == ( ARG_CORE | ARG_FREQ ) ) + { + debug("Changing frequency\n"); + return set_gov("userspace", args.core) | set_speed(args.frequency, args.core); + } + } + // 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; +} diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set/trayfreq_set.c deleted file mode 100644 index 0d65138..0000000 --- a/trayfreq_set/trayfreq_set.c +++ /dev/null @@ -1,163 +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 * - * . * - ************************************************************************/ - - -// : move a lot of this to a .h - -#include -#include -#include -#include -#include - -#include "../freq_tray/getfreq.h" -#include "../freq_tray/getcore.h" -#include "../debug.h" - -#define FILE_PATH_STRING_SIZE 100 - -#define ARG_CORE 0x1 -#define ARG_GOV 0x2 -#define ARG_FREQ 0x4 -typedef struct { - char present; - char *core; - char *governor; - char *frequency; -} argument_summary; - -// - -char write_str_to_file(const char *file, const char *data, const char *core) -{ - FILE *fd; - char file_path[FILE_PATH_STRING_SIZE]; - - // Prepare file path - memset(file_path, '\0', sizeof(file_path)); - 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")) != NULL ) - { - debug("Writing '%s' to '%s'\n",data,file_path); - fprintf(fd, data); - fclose(fd); - return 1; - } - - // Fallthrough: File couldn't be opened for writing - fprintf(stderr, _("FAILED: Couldn't open %s for writing\n") , file_path); - return 0; -} - - -#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) - -void get_argument_summary(int argc, char **argv, argument_summary *argsum) -{ - int arg; - - // Check for -{c,g,f} xyz - for ( arg = 1; arg < argc-1; arg+=2 ) - { - // Can't have empty argument - if ( strlen(argv[arg+1]) != 0 ) - { - if ( strcmp(argv[arg], "-c") == 0 ) - { - // 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; - }