diff options
author | David <dbphillipsnz@gmail.com> | 2014-09-18 22:08:12 +1200 |
---|---|---|
committer | David <dbphillipsnz@gmail.com> | 2014-09-18 22:08:12 +1200 |
commit | 1b1d3f3ea1e5efa95fd1ef18db9e0af517393f95 (patch) | |
tree | a4812e1475f26519dd6945a47e1b7fc226bb4975 | |
parent | 9c6b3292fcd778a06ce54c38c459bc521e045eee (diff) | |
download | paramano-1b1d3f3ea1e5efa95fd1ef18db9e0af517393f95.tar.xz |
Started rename
-rw-r--r-- | Makefile | 56 | ||||
-rw-r--r-- | reload.c | 2 | ||||
-rw-r--r-- | tray.c | 2 | ||||
-rw-r--r-- | trayfreq.c | 152 | ||||
-rw-r--r-- | trayfreq.conf.src | 41 | ||||
-rw-r--r-- | trayfreq.desktop | 7 | ||||
-rw-r--r-- | trayfreq.h | 24 | ||||
-rw-r--r-- | trayfreq_set.c | 160 | ||||
-rw-r--r-- | trayfreq_set_interface.c | 50 | ||||
-rw-r--r-- | trayfreq_set_interface.h | 25 |
10 files changed, 28 insertions, 491 deletions
@@ -1,5 +1,3 @@ -# Tabsize: 4 - # Build utils MAKE = make CC = gcc @@ -13,10 +11,10 @@ LOCALEDIR=$(SHAREDIR)/locale # External program/support programs SUDO=$(BINDIR)/sudo -TRAYFREQ_SET=$(BINDIR)/trayfreq-set +PARAMANO_SET=$(BINDIR)/paramano-set # Misc -TRAYFREQ_CONF=$(SYSCONFDIR)/trayfreq.conf +PARAMANO_CONF=$(SYSCONFDIR)/paramano.conf ROOT_UID=0 @@ -27,8 +25,8 @@ endif EXTRA_CFLAGS+= -DPREFIX=\"$(PREFIX)\" \ -DBINDIR=\"$(BINDIR)\" \ -DSUDO=\"$(SUDO)\" \ - -DTRAYFREQ_SET=\"$(TRAYFREQ_SET)\" \ - -DTRAYFREQ_CONF=\"$(TRAYFREQ_CONF)\" \ + -DPARAMANO_SET=\"$(PARAMANO_SET)\" \ + -DPARAMANO_CONF=\"$(PARAMANO_CONF)\" \ -DLOCALEDIR=\"$(LOCALEDIR)\" \ -DSHAREDIR=\"$(SHAREDIR)\" \ -DROOT_UID=$(ROOT_UID) \ @@ -43,9 +41,9 @@ DEPS = bat_tray.h \ getfreq.h \ getgov.h \ reload.h \ - trayfreq.h \ + paramano.h \ tray.h \ - trayfreq_set_interface.h + paramano_set_interface.h CFLAGS = -I/usr/include/gtk-2.0 \ -I/usr/lib/gtk-2.0/include \ @@ -63,13 +61,13 @@ LDFLAGS = -lgtk-3 \ -lglib-2.0 ######################################################################## # Make entire suite -all: trayfreq trayfreq-set lang trayfreq.conf +all: paramano paramano-set lang paramano.conf ######################################################################## ######################################################################## -# Make main trayfreq system tray program -trayfreq: bat_tray.o \ +# Make main paramano system tray program +paramano: bat_tray.o \ common.o \ config_file.o \ defaults.o \ @@ -77,15 +75,15 @@ trayfreq: bat_tray.o \ getfreq.o \ getgov.o \ reload.o \ - trayfreq.o \ + paramano.o \ tray.o \ - trayfreq_set_interface.o + paramano_set_interface.o $(CC) -o $@ $? $(LDFLAGS) ######################################################################## -# Make trayfreq-set utility -trayfreq-set: \ - trayfreq_set.o \ +# Make paramano-set utility +paramano-set: \ + paramano_set.o \ getcore.o \ getfreq.o \ getgov.o @@ -109,17 +107,17 @@ lang: ######################################################################## # Prepare template config file -trayfreq.conf: +paramano.conf: sed -e 's:SHAREDIR:$(SHAREDIR):g' \ - -e 's:TRAYFREQ_CONF:$(TRAYFREQ_CONF):g' \ - trayfreq.conf.src > trayfreq.conf + -e 's:PARAMANO_CONF:$(PARAMANO_CONF):g' \ + paramano.conf.src > paramano.conf ######################################################################## ######################################################################## # Strip all symbols from binaries strip: - strip -s trayfreq trayfreq-set + strip -s paramano paramano-set ######################################################################## @@ -127,23 +125,21 @@ strip: ######################################################################## # Remove generated files clean: - rm -f trayfreq trayfreq-set *.o lc/*.mo trayfreq.conf + rm -f paramano paramano-set *.o lc/*.mo paramano.conf ######################################################################## ######################################################################## # Install entire suite install: - mkdir -p $(DESTDIR)/$(SHAREDIR)/trayfreq/ - cp -r themes $(DESTDIR)/$(SHAREDIR)/trayfreq/ - - install -Dm 644 lc/fr.mo $(DESTDIR)/$(LOCALEDIR)/fr/LC_MESSAGES/trayfreq.mo + mkdir -p $(DESTDIR)/$(SHAREDIR)/paramano/ + cp -r themes $(DESTDIR)/$(SHAREDIR)/paramano/ - install -Dm 644 trayfreq.conf $(DESTDIR)/etc/trayfreq.conf - install -Dm 644 trayfreq.desktop $(DESTDIR)/etc/xdg/autostart/trayfreq.desktop + install -Dm 644 lc/fr.mo $(DESTDIR)/$(LOCALEDIR)/fr/LC_MESSAGES/paramano.mo - install -Dm 755 trayfreq $(DESTDIR)/$(BINDIR)/trayfreq - install -Dm 755 trayfreq-set $(DESTDIR)/$(BINDIR)/trayfreq-set + install -Dm 644 paramano.conf $(DESTDIR)/$(PARAMANO_CONF) + install -Dm 644 paramano.desktop $(DESTDIR)/etc/xdg/autostart/paramano.desktop - ln -s ../../../etc/trayfreq.conf $(DESTDIR)/$(SHAREDIR)/trayfreq/trayfreq.conf + install -Dm 755 paramano $(DESTDIR)/$(BINDIR)/paramano + install -Dm 755 paramano-set $(DESTDIR)/$(PARAMANO_SET) ######################################################################## @@ -19,7 +19,7 @@ #include "reload.h" #include "bat_tray.h" #include "tray.h" -#include "trayfreq.h" +#include "paramano.h" #include "defaults.h" #include "common.h" #include <stdio.h> @@ -21,7 +21,7 @@ #include "getfreq.h" #include "getcore.h" #include "getgov.h" -#include "trayfreq_set_interface.h" +#include "paramano_set_interface.h" #include "bat_tray.h" #include "defaults.h" #include "common.h" diff --git a/trayfreq.c b/trayfreq.c deleted file mode 100644 index 49c1c5a..0000000 --- a/trayfreq.c +++ /dev/null @@ -1,152 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq-archlinux. * - * * - * trayfreq-archlinux is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * trayfreq-archlinux is distributed in the hope that it will be useful,* - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with trayfreq-archlinux. If not, see * - * <http://www.gnu.org/licenses/>. * - ************************************************************************/ - -#include "trayfreq.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 "common.h" - -#include <gtk/gtk.h> -#include <unistd.h> // getuid, getgid -#include <stdio.h> // printf, FILE, fopen, etc -#include <string.h> // strlen - -#include <libintl.h> // gettext -#include <locale.h> // LC_ALL etc - - -/*********************************************************************** - * Main - **********************************************************************/ -int main(int argc, char** argv) -{ - setlocale(LC_ALL, ""); - bindtextdomain("trayfreq",LOCALEDIR); - textdomain("trayfreq"); - debug("Set gettext up\n"); - - if(!gtk_init_check(&argc, &argv)) - { - debug("Couldn't start gtk\n"); - g_error( _("GTK Error: gtk_init_check returned FALSE.\nBailing.") ); - return 1; - } - - struct sigaction sig_act; - sig_act.sa_handler = reload_config; - sig_act.sa_flags = 0; - sigemptyset(&sig_act.sa_mask); - - if (sigaction(SIGUSR1, &sig_act, NULL) == -1) - { - debug("Couldn't set sigaction for SIGUSR1\n"); - } - config_init(); - gc_init(); - gg_init(); - gf_init(); - tray_init(); - tray_show(); - - // Show battery tray only if we're supposed to - if(_DEFAULT_SHOW_BATTERY) - { - debug("Showing battery info this time around\n"); - bat_tray_init(); - bat_tray_show(); - } - - debug("Passing control to Gtk\n"); - - gtk_main(); - debug("Exiting main()\n"); - return 0; -} - - -/*********************************************************************** - * Load config - **********************************************************************/ -void config_init() -{ - struct config_file config; - FILE* fd = NULL; - gboolean home_config_exists; - config.key_file = NULL; - - config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.conf", NULL); - - - // Check if ~/.trayfreq.config exists - if( (fd = fopen(config.file_name, "r")) ) - { - // If file exists, close it, set param to TRUE - debug("Found '%s'\n",config.file_name); - fclose(fd); - home_config_exists = TRUE; - } else { - // If file didn't exist, it's not open (don't close it), free filename var, set param to FALSE - debug("Didn't find '%s'\n",config.file_name); - g_free(config.file_name); - home_config_exists = FALSE; - } - - if(!home_config_exists) - config.file_name = g_strconcat(TRAYFREQ_CONF, NULL); - - gboolean success = config_open(&config); - if(!success) - { - debug("Couldn't open '%s' for reading\n",config.file_name); - 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"); - _DEFAULT_AC_GOV = config_get_key(&config, "ac", "governor"); - - char* temp = config_get_key(&config, "battery", "show"); - if (temp) - _DEFAULT_SHOW_BATTERY = ( temp[0] == '1' ); - - info("UID: %d GID: %d\n", getuid(), getgid()); - - temp = config_get_key(&config, "extra", "theme"); - if (temp && strlen(temp) < sizeof(_DEFAULT_THEME) ) - { - sprintf(_DEFAULT_THEME, "%s", temp); - } - - debug("Using theme %s\n",_DEFAULT_THEME); - - g_free(config.file_name); - config_close(&config); -} - diff --git a/trayfreq.conf.src b/trayfreq.conf.src deleted file mode 100644 index b2e4500..0000000 --- a/trayfreq.conf.src +++ /dev/null @@ -1,41 +0,0 @@ -# -# Begin TRAYFREQ_CONF -# -# Template/default config file for trayfreq-archlinux -# - -[battery] -## Uncomment to hide battery icon -- useful for desktop PCs -## Set to anything (or leave unset/commented out) to show battery icon -# show=0 - -## Name of the governor to use for all cores when on battery power -## Get a space-separated list of available governors from -## /sys/devices/system/cpu/cpuX/cpufreq/scaling_available_governors -# governor=powersave - -[ac] -## Governor to use for all core while on AC power -## Often set to a performance or non-power-saving governor -# governor=ondemand - -[governor] -## Governor to set all cores to when trayfreq starts -# default=ondemand - - -[frequency] -## The frequency to set the CPU to when trayfreq starts -## Get a space-separated list of available frequencies from -## /sys/devices/system/cpu/cpuX/cpufreq/scaling_available_frequencies -# default=800000 - - -[extra] -## If you're arty, you can put together your own theme and point trayfreq to it -# theme=SHAREDIR/trayfreq/themes/some-theme/ - - -# -# End TRAYFREQ_CONF -# diff --git a/trayfreq.desktop b/trayfreq.desktop deleted file mode 100644 index 0905549..0000000 --- a/trayfreq.desktop +++ /dev/null @@ -1,7 +0,0 @@ -[Desktop Entry] -Version=1.0 -Encoding=UTF-8 -Name=trayfreq -GenericName=trayfreq -Exec=/usr/bin/trayfreq -Type=Application diff --git a/trayfreq.h b/trayfreq.h deleted file mode 100644 index af1c8b0..0000000 --- a/trayfreq.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq-archlinux. * - * * - * trayfreq-archlinux is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * trayfreq-archlinux is distributed in the hope that it will be useful,* - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with trayfreq-archlinux. If not, see * - * <http://www.gnu.org/licenses/>. * - ************************************************************************/ - -#ifndef TRAYFREQ_H -#define TRAYFREQ_H - -void config_init(); - -#endif diff --git a/trayfreq_set.c b/trayfreq_set.c deleted file mode 100644 index 02b0eef..0000000 --- a/trayfreq_set.c +++ /dev/null @@ -1,160 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq-archlinux. * - * * - * trayfreq-archlinux is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * trayfreq-archlinux is distributed in the hope that it will be useful,* - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with trayfreq-archlinux. If not, see * - * <http://www.gnu.org/licenses/>. * - ************************************************************************/ - - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <libintl.h> -#include <locale.h> - -#include "getfreq.h" -#include "getcore.h" -#include "common.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,""); - bindtextdomain("trayfreq",LOCALEDIR); - 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) - { - - debug ("Checking UID\n"); - if (getuid() != 0) - fprintf(stderr,"Warning: running as UID %d, not 0\n",getuid() ); - - 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_interface.c b/trayfreq_set_interface.c deleted file mode 100644 index df168c6..0000000 --- a/trayfreq_set_interface.c +++ /dev/null @@ -1,50 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq-archlinux. * - * * - * trayfreq-archlinux is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * trayfreq-archlinux is distributed in the hope that it will be useful,* - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with trayfreq-archlinux. If not, see * - * <http://www.gnu.org/licenses/>. * - ************************************************************************/ - -#include "trayfreq_set_interface.h" - -#include "common.h" -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -void si_gov(char* gov, int core) -{ - char cmd[1024]; - if (getuid() != ROOT_UID) - { - sprintf(cmd, SUDO" -n "TRAYFREQ_SET" -g %s -c %i &",gov,core); - } else { - sprintf(cmd, TRAYFREQ_SET" -g %s -c %i",gov,core); - } - info("Running '%s'\n",cmd); - system(cmd); -} - -void si_freq(int freq, int core) -{ - char cmd[1024]; - if (getuid() != ROOT_UID) - { - sprintf(cmd, SUDO" -n "TRAYFREQ_SET" -f %i -c %i &",freq,core); - } else { - sprintf(cmd, TRAYFREQ_SET" -f %i -c %i",freq,core); - } - info("Running '%s'\n",cmd); - system(cmd); -} diff --git a/trayfreq_set_interface.h b/trayfreq_set_interface.h deleted file mode 100644 index bdbf652..0000000 --- a/trayfreq_set_interface.h +++ /dev/null @@ -1,25 +0,0 @@ -/************************************************************************ - * This file is part of trayfreq-archlinux. * - * * - * trayfreq-archlinux is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * trayfreq-archlinux is distributed in the hope that it will be useful,* - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with trayfreq-archlinux. If not, see * - * <http://www.gnu.org/licenses/>. * - ************************************************************************/ - -#ifndef TRAYFREQ_SET_INTERFACE_H -#define TRAYFREQ_SET_INTERFACE_H - -void si_gov(char* gov, int core); -void si_freq(int freq, int core); - -#endif |