diff options
| author | David <dbphillipsnz@gmail.com> | 2014-05-10 14:10:41 +1200 | 
|---|---|---|
| committer | David <dbphillipsnz@gmail.com> | 2014-05-10 14:10:41 +1200 | 
| commit | c6b5a3477b87ced86356813a578c19f6b345008b (patch) | |
| tree | 5c7355d973296c1a5981319f712a3d0f9928dcca | |
| parent | 68c8dfd0de28f61f27b20de271d2776219a30895 (diff) | |
| parent | e05ece0acdc38ecf16e3ed2088a557248537d2a7 (diff) | |
| download | paramano-c6b5a3477b87ced86356813a578c19f6b345008b.tar.xz | |
Merge branch 'reload-config' Conflicts: Makefile
| -rw-r--r-- | Makefile | 65 | ||||
| -rw-r--r-- | bat_tray.c (renamed from bat_tray/bat_tray.c) | 1 | ||||
| -rw-r--r-- | bat_tray.h (renamed from bat_tray/bat_tray.h) | 3 | ||||
| -rw-r--r-- | defaults.c | 12 | ||||
| -rw-r--r-- | defaults.h | 5 | ||||
| -rw-r--r-- | getcore.c (renamed from freq_tray/getcore.c) | 0 | ||||
| -rw-r--r-- | getcore.h (renamed from freq_tray/getcore.h) | 2 | ||||
| -rw-r--r-- | getfreq.c (renamed from freq_tray/getfreq.c) | 0 | ||||
| -rw-r--r-- | getfreq.h (renamed from freq_tray/getfreq.h) | 0 | ||||
| -rw-r--r-- | getgov.c (renamed from freq_tray/getgov.c) | 0 | ||||
| -rw-r--r-- | getgov.h (renamed from freq_tray/getgov.h) | 0 | ||||
| -rw-r--r-- | reload.c | 34 | ||||
| -rw-r--r-- | reload.h | 27 | ||||
| -rw-r--r-- | tray.c | 57 | ||||
| -rw-r--r-- | tray.h | 11 | ||||
| -rw-r--r-- | trayfreq.c | 40 | ||||
| -rw-r--r-- | trayfreq.h | 43 | ||||
| -rw-r--r-- | trayfreq_set.c (renamed from trayfreq_set/trayfreq_set.c) | 6 | ||||
| -rw-r--r-- | trayfreq_set_interface.c (renamed from trayfreq_set/trayfreq_set_interface.c) | 4 | ||||
| -rw-r--r-- | trayfreq_set_interface.h (renamed from trayfreq_set/trayfreq_set_interface.h) | 2 | 
20 files changed, 240 insertions, 72 deletions
| @@ -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 @@ -38,7 +51,8 @@ trayfreq_SOURCES		=	freq_tray/getcore.c \  							config_file.c \  							defaults.c \  							bat_tray/bat_tray.c \ -							common.c +							common.c \ +							reload.c  trayfreq_set_CFLAGS		=	$(GLIB_CFLAGS) -Wall -D_=gettext  trayfreq_set_LDFLAGS	=	$(GLIB_LIBS) -lm @@ -54,19 +68,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: @@ -77,7 +113,7 @@ lang:  ########################################################################  # Remove generated files  clean: -	rm -f trayfreq trayfreq-set lc/*.mo +	rm -f trayfreq trayfreq-set *.o lc/*.mo  ######################################################################## @@ -85,14 +121,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/bat_tray.c b/bat_tray.c index 0037ce4..2f6c7d3 100644 --- a/bat_tray/bat_tray.c +++ b/bat_tray.c @@ -18,7 +18,6 @@  #include "bat_tray.h" -#include "../common.h"  #include <gtk/gtk.h>  #include <string.h> diff --git a/bat_tray/bat_tray.h b/bat_tray.h index 1d4c993..583de57 100644 --- a/bat_tray/bat_tray.h +++ b/bat_tray.h @@ -20,7 +20,8 @@  #define BAT_TRAY_H  #include <glib.h> -#include "../debug.h" +#include "debug.h" +#include "common.h"  #define STATE_CHARGING		0  #define STATE_DISCHARGING	1 @@ -23,4 +23,16 @@ char* _DEFAULT_FREQ;  char* _DEFAULT_PROG;  char* _DEFAULT_BAT_GOV;  char* _DEFAULT_AC_GOV; +bool  _DEFAULT_SHOW_BATTERY = TRUE;  bool  _DEFAULT_USE_SUDO	= FALSE; + +void defaults_init() +{ +	_DEFAULT_GOV			= NULL; +	_DEFAULT_FREQ			= NULL; +	_DEFAULT_PROG			= NULL; +	_DEFAULT_BAT_GOV		= NULL; +	_DEFAULT_AC_GOV			= NULL; +	_DEFAULT_SHOW_BATTERY	= TRUE; +	_DEFAULT_USE_SUDO		= FALSE;	 +} @@ -20,12 +20,17 @@  #define DEFAULTS_H  #include "bool.h" +#include <stdlib.h>  char* _DEFAULT_GOV;  char* _DEFAULT_FREQ;  char* _DEFAULT_PROG;  char* _DEFAULT_BAT_GOV;  char* _DEFAULT_AC_GOV; +bool  _DEFAULT_SHOW_BATTERY;  bool  _DEFAULT_USE_SUDO; + +void defaults_init(); +  #endif /* ifndef DEFAULTS_H */ diff --git a/freq_tray/getcore.c b/getcore.c index ad4878f..ad4878f 100644 --- a/freq_tray/getcore.c +++ b/getcore.c diff --git a/freq_tray/getcore.h b/getcore.h index 43dcd12..67d2f41 100644 --- a/freq_tray/getcore.h +++ b/getcore.h @@ -19,7 +19,7 @@  #ifndef GETCORE_H  #define GETCORE_H -#include "../debug.h" +#include "debug.h"  void gc_init();  int  gc_number(); diff --git a/freq_tray/getfreq.c b/getfreq.c index 4b00775..4b00775 100644 --- a/freq_tray/getfreq.c +++ b/getfreq.c diff --git a/freq_tray/getfreq.h b/getfreq.h index 8df9eca..8df9eca 100644 --- a/freq_tray/getfreq.h +++ b/getfreq.h diff --git a/freq_tray/getgov.c b/getgov.c index 181ad41..181ad41 100644 --- a/freq_tray/getgov.c +++ b/getgov.c diff --git a/freq_tray/getgov.h b/getgov.h index fca341d..fca341d 100644 --- a/freq_tray/getgov.h +++ b/getgov.h diff --git a/reload.c b/reload.c new file mode 100644 index 0000000..6b78dac --- /dev/null +++ b/reload.c @@ -0,0 +1,34 @@ +/************************************************************************ + * This file is part of trayfreq-archlinux.                             * + *                                                                      * + * trayfreq-archlinux is free software; you can redistribute it and/or  * + * modify it under the terms of the GNU General Public License as       * + * published by the Free Software Foundation; either version 3 of the   * + * License, or (at your option) any later version.                      * + *                                                                      * + * trayfreq-archlinux is distributed in the hope that it will be useful,* + * but WITHOUT ANY WARRANTY; without even the implied warranty of       * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        * + * GNU General Public License for more details.                         * + *                                                                      * + * You should have received a copy of the GNU General Public License    * + * along with trayfreq-archlinux. If not, see                           * + * <http://www.gnu.org/licenses/>.                                      * + ************************************************************************/ + +#include "reload.h" + +void reload_config() +{ +	debug("Reloading config\n"); +	config_init(); +	if (_DEFAULT_SHOW_BATTERY) +	{ +		//bat_tray_hide(); +		bat_tray_show(); +	} else { +		bat_tray_hide(); +	} +	debug("Re-init freq tray\n"); +	tray_set_defaults(); +} diff --git a/reload.h b/reload.h new file mode 100644 index 0000000..f3b974a --- /dev/null +++ b/reload.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                           * + * <http://www.gnu.org/licenses/>.                                      * + ************************************************************************/ + +#ifndef RELOAD_H +#define RELOAD_H +#include "trayfreq.h" +#include "defaults.h" +#include "bat_tray.h" +#include <stdio.h> + +void reload_config(); +#endif @@ -164,30 +164,6 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean  	memset(msg, '\0', sizeof(msg));  	memset(current_governor, '\0', sizeof(current_governor) ); - -	switch ( get_battery_state() ) -	{ -		case STATE_DISCHARGING: -			debug("Discharging\n"); -			if(_DEFAULT_BAT_GOV) -			{ -				for(i = 0; i < gc_number(); ++i) -					si_gov(_DEFAULT_BAT_GOV, i); -			} -			break; - -		case STATE_CHARGING: -		case STATE_FULL: -			debug("Charging/Full\n"); -			if(_DEFAULT_AC_GOV) -			{ -				for(i = 0; i < gc_number(); ++i) -					si_gov(_DEFAULT_AC_GOV, i); -			} - -			break; -	} -  	gg_current(0, current_governor, sizeof(current_governor) );  	sprintf(msg+strlen(msg), _("Governor: %s\n"), current_governor); @@ -215,12 +191,36 @@ static void popup_menu(GtkStatusIcon* statuc_icon,guint button,guint activate_ti  static gboolean update_icon(gpointer user_data)  { +	int i; +	switch ( get_battery_state() ) +	{ +		case STATE_DISCHARGING: +			debug("Discharging\n"); +			if(_DEFAULT_BAT_GOV) +			{ +				for(i = 0; i < gc_number(); ++i) +					si_gov(_DEFAULT_BAT_GOV, i); +			} +			break; + +		case STATE_CHARGING: +		case STATE_FULL: +			debug("Charging/Full\n"); +			if(_DEFAULT_AC_GOV) +			{ +				for(i = 0; i < gc_number(); ++i) +					si_gov(_DEFAULT_AC_GOV, i); +			} + +			break; +	} +  	debug("Updating icon\n");  	tray_update_icon_percent();  	return TRUE;  } -void tray_init() +void tray_set_defaults()  {  	// Set defaults  	int i = 0; @@ -240,6 +240,11 @@ void tray_init()  			si_freq(atoi(_DEFAULT_FREQ), i);  	} +} + +void tray_init() +{ +	tray_set_defaults();  	tray = gtk_status_icon_new();  	gchar* icon_file = g_strconcat("/usr/share/trayfreq/cpufreq-0.png", NULL); @@ -268,7 +273,7 @@ void tray_update_icon_percent()  	gulong max_frequency = gf_freqi(0, 0);  	gint adjusted_percent = 0;  	// If no governor, set percentage to 0. This if statement fixes an FPE a few lines down -	if (max_frequency == 0) +	if (gg_number() == 0)  	{  		adjusted_percent = 0;  	} else { @@ -22,11 +22,11 @@  #include <glib.h>  #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 <gtk/gtk.h> @@ -36,6 +36,7 @@  #include <libintl.h> +void     tray_set_defaults();  void     tray_init();  void     tray_set_tooltip(const gchar* msg);  void     tray_update_icon_percent(); @@ -16,24 +16,7 @@   * <http://www.gnu.org/licenses/>.                                      *   ************************************************************************/ -#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 <gtk/gtk.h> -#include <glib.h> -#include <stdlib.h> -#include <stdio.h> -#include <libintl.h> -#include <locale.h> - -static gboolean SHOW_BATTERY = TRUE; +#include "trayfreq.h"  void config_init()  { @@ -69,6 +52,10 @@ void config_init()  		g_warning(_("Failed to open config files!\n"));  		return;  	} + +	// Reset defaults to default values +	defaults_init(); +  	_DEFAULT_GOV		= config_get_key(&config, "governor", "default");  	_DEFAULT_FREQ		= config_get_key(&config, "frequency", "default");  	_DEFAULT_BAT_GOV	= config_get_key(&config, "battery", "governor"); @@ -76,12 +63,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 +92,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 +110,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                           * + * <http://www.gnu.org/licenses/>.                                      * + ************************************************************************/ + +#ifndef TRAYFREQ_H +#define TRAYFREQ_H + +#include "widget_manager.h" +#include "tray.h" +#include "bat_tray.h" +#include "getfreq.h" +#include "getcore.h" +#include "getgov.h" +#include "config_file.h" +#include "reload.h" +#include "defaults.h" +#include "debug.h" + +#include <gtk/gtk.h> +#include <glib.h> +#include <stdlib.h> +#include <stdio.h> +#include <libintl.h> +#include <locale.h> + +void config_init(); +//int main(int argc, char** argv); + +#endif diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set.c index 0d65138..785b93b 100644 --- a/trayfreq_set/trayfreq_set.c +++ b/trayfreq_set.c @@ -25,9 +25,9 @@  #include <libintl.h>  #include <locale.h> -#include "../freq_tray/getfreq.h" -#include "../freq_tray/getcore.h" -#include "../debug.h" +#include "getfreq.h" +#include "getcore.h" +#include "debug.h"  #define FILE_PATH_STRING_SIZE 100 diff --git a/trayfreq_set/trayfreq_set_interface.c b/trayfreq_set_interface.c index 3e26112..e64a88e 100644 --- a/trayfreq_set/trayfreq_set_interface.c +++ b/trayfreq_set_interface.c @@ -18,6 +18,8 @@  #include "trayfreq_set_interface.h" +#include "debug.h" +  #include <stdio.h>  #include <stdlib.h> @@ -30,6 +32,7 @@ void si_gov(char* gov, int core)  	} else {  		sprintf(cmd, "trayfreq-set -g %s -c %i",gov,core);  	} +	debug("Running '%s'\n",cmd);  	system(cmd);  } @@ -42,5 +45,6 @@ void si_freq(int freq, int core)  	} else {  		sprintf(cmd, "trayfreq-set -f %i -c %i",freq,core);  	} +	debug("Running '%s'\n",cmd);  	system(cmd);  } diff --git a/trayfreq_set/trayfreq_set_interface.h b/trayfreq_set_interface.h index c5681e4..bdc13a3 100644 --- a/trayfreq_set/trayfreq_set_interface.h +++ b/trayfreq_set_interface.h @@ -19,7 +19,7 @@  #ifndef TRAYFREQ_SET_INTERFACE_H  #define TRAYFREQ_SET_INTERFACE_H -#include "../defaults.h" +#include "defaults.h"  void si_gov(char* gov, int core);  void si_freq(int freq, int core); | 
