diff options
Diffstat (limited to 'src/osdsh')
-rw-r--r-- | src/osdsh/Makefile | 48 | ||||
-rw-r--r-- | src/osdsh/apmwatch.c | 140 | ||||
-rw-r--r-- | src/osdsh/clockdisplay.c | 100 | ||||
-rw-r--r-- | src/osdsh/connectionwatch.c | 171 | ||||
-rw-r--r-- | src/osdsh/controlsh.c | 248 | ||||
-rw-r--r-- | src/osdsh/mixerwatch.c | 161 | ||||
-rw-r--r-- | src/osdsh/osdsh.c | 175 | ||||
-rw-r--r-- | src/osdsh/osdsh.h | 44 | ||||
-rw-r--r-- | src/osdsh/utils.c | 97 |
9 files changed, 1184 insertions, 0 deletions
diff --git a/src/osdsh/Makefile b/src/osdsh/Makefile new file mode 100644 index 0000000..d0f28ca --- /dev/null +++ b/src/osdsh/Makefile @@ -0,0 +1,48 @@ +CC = gcc +PREFIX = /usr +BINDIR = $(PREFIX)/bin +DOCDIR = $(PREFIX)/doc/osdsh +LIBDIR = -L/usr/X11R6/lib -L/usr/lib +LIBS = $(LIBDIR) -lxosd -lpthread +CFLAGS = -O3 + +#APMOBJS = apmwatch.o +#APMLIBS = -lapm +#APM=1 + +OBJS = controlsh.o utils.o + +all: osdsh libs + +libs: libosdshclock.so libosdshmixer.so libosdshapm.so libosdshnet.so + +%.o: %.c + + gcc -c $< + +osdsh: $(OBJS) + gcc -c $(CFLAGS) $@.c + gcc $(CFLAGS) -o $@ osdsh.o $(OBJS) $(LIBS) –ldl + +clean: libclean + rm osdsh + rm *.o + +libclean: + rm libosdsh*.so + +libosdshclock.so: + gcc -fPIC -c clockdisplay.c + gcc -shared -o $@ clockdisplay.o utils.o + +libosdshmixer.so: + gcc -fPIC -c mixerwatch.c + gcc -shared -o $@ mixerwatch.o utils.o + +libosdshapm.so: + gcc -fPIC -c apmwatch.c + gcc -shared -o $@ apmwatch.o utils.o -lapm + +libosdshnet.so: + gcc -fPIC -c connectionwatch.c + gcc -shared -o $@ connectionwatch.o utils.o diff --git a/src/osdsh/apmwatch.c b/src/osdsh/apmwatch.c new file mode 100644 index 0000000..5c5f424 --- /dev/null +++ b/src/osdsh/apmwatch.c @@ -0,0 +1,140 @@ +#include "osdsh.h" +#include "../config.h" +#include <apm.h> +#define IAM 2 +#define MYNAME "APM / Battery" + +settings_t apmset; +void *apm_watch(void *arg); + +/* ========================================================================== + ====================== REQUIERED STUFF FOR PLUGINS ======================= + ========================================================================== + +***** ID of the plugin, contact me before you asign this to your plugin!! ***** +*/ + +int whoami(void) { + return IAM; +} + +/* Return a pointer to the name of the plugin */ +char *mynameis() { + char *a = MYNAME; + return a; +} + +/* This function sets the default (initual) values for our osd */ +void initialize_myosd() { + set_defaults(&apmset); +} + +/* This function takes a command and arguments, if the command is ours, execute + it and return 1, if not, return 0*/ + +int isitmine( char command[BUFSIZ], char arg_first[BUFSIZ], + char arg_secound[BUFSIZ]) +{ + int i=1; + + if(strcmp(command, "stop")==0) { + apmset.displaying = 0; + } + else if(strcmp(command, "start")==0) { + if(!apmset.displaying) { + apmset.displaying = 1; + pthread_create(&apmset.mythread, NULL, apm_watch, NULL); + } + } + else if (strcmp(command, "apmw")==0) { + if (atoi(arg_first)) { + isitmine("start", NULL, NULL); + } + else { + apmset.displaying = 0; + } + } + else if (strcmp(command, "apms")==0) { + isitmine("start", NULL, NULL); + sleep(atoi(arg_first)); + apmset.displaying = 0; + } + else if (strcmp(command, "sapm")==0) { + control_options(&apmset, arg_first, arg_secound); + } + else { + i = 0; + } + return i; +} + +/*=============================apm_watch()=========================== */ +/* some ideas (shamelessly copied ) from apmd's "apm" utility*/ +void *apm_watch(void *arg) +{ + int secs; + apm_info i; + char battery[255]; + char remainingtime[255]; + char report1[255]; + + apmset.myosd = xosd_create(2); + initialize_osd(&apmset); + + while(apmset.displaying) { + if (apm_read(&i)) + { + /*fprintf(stderr, "Cannot read APM information\n");*/ + apmset.displaying = 0; + xosd_display(apmset.myosd, apmset.position==XOSD_bottom?1:0, XOSD_string, + "Cannot read APM information"); + break; + } + secs = i.using_minutes ? i.battery_time * 60 : i.battery_time; + if (i.battery_flags != 0xff /* Have a 1.1 BIOS and a system battery. ?????? */ + && i.battery_flags & 0x80) { + sprintf(battery, "no system battery"); + } + else { + switch (i.battery_status) { + case 0: + sprintf(battery, "high"); + xosd_set_colour(apmset.myosd, apmset.color); + break; + case 1: + sprintf(battery, "low"); + xosd_set_colour(apmset.myosd, "yellow"); + break; + case 2: + sprintf(battery, "critical!!"); + xosd_set_colour(apmset.myosd, "red"); + break; + case 3: + sprintf(battery, "charging..."); + break; + } + + } + if (strcmp(battery, "no system battery")==0) { + xosd_display(apmset.myosd, apmset.position==XOSD_bottom?1:0, XOSD_string, + "AC on line"); + xosd_display(apmset.myosd, apmset.position==XOSD_bottom?0:1, XOSD_string, battery); + } + else { + sprintf(remainingtime, "%dhr, %dmin, %dsec", + secs/3600, + (secs%3600)/60, + ((secs%3600)%60)%60); + sprintf(report1, "AC: %s Remaining battery: %d%%(%s) %s", + i.ac_line_status?"on line":"off line",i.battery_percentage, + remainingtime, battery); + + xosd_display(apmset.myosd, 0, XOSD_string, report1); + if (apmset.displaying > 1) + xosd_display(apmset.myosd, 1, XOSD_percentage, i.battery_percentage ); + else + xosd_display(apmset.myosd, 1, XOSD_string, ""); + } + } + pthread_exit(0); +} diff --git a/src/osdsh/clockdisplay.c b/src/osdsh/clockdisplay.c new file mode 100644 index 0000000..ca057b3 --- /dev/null +++ b/src/osdsh/clockdisplay.c @@ -0,0 +1,100 @@ +#include "../config.h" +#include "osdsh.h" +#define IAM 1 +#define MYNAME "Clock" + +char clockformat[255] = CLOCK_FORMAT; + +void *osdsh_clock(void *arg); +settings_t clocksetts; + +/*================================clock_display() ========================== */ +/* got the ideas from osd_clock */ + + +/* ========================================================================== + ====================== REQUIERED STUFF FOR PLUGINS ======================= + ========================================================================== + +***** ID of the plugin, contact me before you asign this to your plugin!! ***** +*/ +int whoami(void) { + return IAM; +} + +/* Return a pointer to the name of the plugin */ +char *mynameis() { + char *a = MYNAME; + return a; +} + +/* This function sets the default (initual) values for our osd */ +void initialize_myosd() { + set_defaults(&clocksetts); +} + +/* This function takes a command and arguments, if the command is ours, execute + it and return 1, if not, return 0*/ + +int isitmine( char command[BUFSIZ], char arg_first[BUFSIZ], + char arg_secound[BUFSIZ]) +{ + int i=1; + + if(strcmp(command, "stop")==0) { + clocksetts.displaying = 0; + } + else if(strcmp(command, "start")==0) { + if(!clocksetts.displaying) { + clocksetts.displaying = 1; + pthread_create(&clocksetts.mythread, NULL, osdsh_clock, NULL); + } + } + else if (strcmp(command, "clkf")==0) { + strcpy(clockformat ,arg_first); + } + else if (strcmp(command, "clck")==0) { + if (atoi(arg_first)) { + isitmine("start", NULL, NULL); + } + else { + clocksetts.displaying = 0; + } + } + else if (strcmp(command, "time")==0) { + if (atoi(arg_first)) + isitmine("start", NULL, NULL); + sleep(atoi(arg_first)); + clocksetts.displaying = 0; + } + else if (strcmp(command, "sclk")==0) { + control_options(&clocksetts, arg_first, arg_secound); + } + else { + i = 0; + } + return i; +} + +/*The functtion to call when we start our plugin... this sould be called by a +pthread(...) call so it won't block the whole program*/ + +void *osdsh_clock(void *arg) +{ + time_t currenttime; + char timestring[255]; + + clocksetts.myosd = xosd_create(1); + initialize_osd(&clocksetts); + clocksetts.displaying = 1; + + while (clocksetts.displaying) { + currenttime = time(0); + + strftime(timestring, 255, clockformat, localtime(¤ttime)); + + xosd_display(clocksetts.myosd, 0, XOSD_string, timestring); + } + xosd_destroy(clocksetts.myosd); + pthread_exit(0); +} diff --git a/src/osdsh/connectionwatch.c b/src/osdsh/connectionwatch.c new file mode 100644 index 0000000..804eaa1 --- /dev/null +++ b/src/osdsh/connectionwatch.c @@ -0,0 +1,171 @@ +#include "osdsh.h" +#include "../config.h" +#define IAM 3 +#define MYNAME "Net" + +settings_t pppset; +void *connection_watch(void *arg); + +char pppdevice[PATH_MAX+1]; +char connecting1[BUFSIZ+1]; +char connecting2[BUFSIZ+1]; +char connected1[BUFSIZ+1]; +char connected2[BUFSIZ+1]; +char disconnected[BUFSIZ+1]; +char timeconnected[255]; + +/* ========================================================================== + ====================== REQUIERED STUFF FOR PLUGINS ======================= + ========================================================================== + +***** ID of the plugin, contact me before you asign this to your plugin!! ***** +*/ + +int whoami(void) { + return IAM; +} + +/* Return a pointer to the name of the plugin */ +char *mynameis() { + char *a = MYNAME; + return a; +} + +/* This function sets the default (initual) values for our osd */ +void initialize_myosd() { + set_defaults(&pppset); +} + +/* This function takes a command and arguments, if the command is ours, execute + it and return 1, if not, return 0*/ + +int isitmine( char command[BUFSIZ], char arg_first[BUFSIZ], + char arg_secound[BUFSIZ]) +{ + int i=1; + + if(strcmp(command, "stop")==0) { + pppset.displaying = 0; + } + else if(strcmp(command, "start")==0) { + if(!pppset.displaying) { + pppset.displaying = 1; + pthread_create(&pppset.mythread, NULL, connection_watch, NULL); + } + } + else if (strcmp(command, "pppw")==0) { + if (atoi(arg_first)) { + isitmine("start", NULL, NULL); + } + else { + pppset.displaying = 0; + } + } + else if (strcmp(command, "sppp")==0) { + control_options(&pppset, arg_first, arg_secound); + } + else if (strcmp(command, "pdev")==0) { + sprintf(pppdevice, "%s", arg_first); + } + else if (strcmp(command, "connecting")==0) { + sprintf(connecting1, "%s", arg_first); + sprintf(connecting2, "%s", arg_secound); + } + else if (strcmp(command, "connected")==0) { + sprintf(connected1, "%s", arg_first); + sprintf(connected2, "%s", arg_secound); + } + else if (strcmp(command, "disconnected")==0) { + sprintf(disconnected, "%s", arg_first); + } + else if (strcmp(command, "showconntime")==0) { + xosd_display(pppset.myosd, 0, XOSD_string, "Connected for"); + xosd_display(pppset.myosd, 1, XOSD_string, timeconnected); + } + else { + i = 0; + } + return i; +} + + +/*=============================connection_watch()=========================== */ +/* some ideas from ppptime */ +void *connection_watch(void *arg) +{ + FILE *fp; + int ppp0run; + + long start; + long end; + int total; + struct stat st; + + char ppp0pidfile[PATH_MAX]; + + pppset.myosd = xosd_create(2); + initialize_osd(&pppset); + + if(strcmp(pppdevice, "")==0) + sprintf(pppdevice, "%s", PPP_DEVICE); + + sprintf(ppp0pidfile, "%s/%s.pid", PPP_PID_PATH, pppdevice); + + if (strcmp(connecting1, "")==0) + sprintf(connecting1, "Connecting"); + if (strcmp(connecting2, "")==0) + sprintf(connecting2, "please wait..."); + + if (strcmp(connected1, "")==0) + sprintf(connected1, "Connected"); + if (strcmp(connected2, "")==0) + sprintf(connected2, "GO!"); + + if (strcmp(disconnected, "")==0) + sprintf(disconnected, "Connection terminated"); + + while (pppset.displaying) { + + xosd_display(pppset.myosd, 0, XOSD_string, connecting1); + xosd_display(pppset.myosd, 1, XOSD_string, connecting2); + + sprintf(ppp0pidfile, "%s/%s.pid", PPP_PID_PATH, pppdevice); + + if((fp=fopen(ppp0pidfile, "r"))==NULL) { + ppp0run = 0; + } + else { + ppp0run = 1; + fclose(fp); + } + + if(ppp0run) { + xosd_display(pppset.myosd,0, XOSD_string, connected1); + xosd_display(pppset.myosd,1, XOSD_string, connected2); + + stat(ppp0pidfile, &st); + start = st.st_mtime; + + while((fp=fopen(ppp0pidfile, "r"))!=NULL) { + fclose(fp); + end = time(0); + total = end - start; + sprintf(timeconnected, "Connected for %d hr %d min %d sec", + ((total/60)/60)%100, (total/60)%60, total%60); + usleep(3); + } + end = time(0); + total = end - start; + sprintf(timeconnected, "Disconnected after %d hr %d min %d sec", + ((total/60)/60)%100, (total/60)%60, total%60); + + xosd_display(pppset.myosd,0, XOSD_string, disconnected); + xosd_display(pppset.myosd,1, XOSD_string, timeconnected); + + pppset.displaying = 0; + } + } + sleep(1); + xosd_destroy(pppset.myosd); + pthread_exit(0); +} diff --git a/src/osdsh/controlsh.c b/src/osdsh/controlsh.c new file mode 100644 index 0000000..de637db --- /dev/null +++ b/src/osdsh/controlsh.c @@ -0,0 +1,248 @@ +#include "osdsh.h" +#include "../config.h" + + int n=0; + plugininfo_t plugins[MAX_PLUGINS]; + settings_t settings; + +/* ================================== load a plugin ============================= */ +int load_plugin( char pluginfile[255]) +{ + int (*info)(); + void *module; + int a; + + char file[PATH_MAX+256]; + char *msg = NULL; + + +/* getcwd(file, PATH_MAX); + strcat(file, "/"); +*/ + strcat(file, pluginfile); + + module = dlopen(pluginfile, RTLD_NOW); + + if(!module) { + msg = dlerror(); + if(msg != NULL) { + fprintf(stderr, "%s\n", msg); + a = -1; + } + } + else { + info = dlsym(module, "whoami"); + a = info(); + + info = dlsym(module, "initialize_myosd"); + info(); + + plugins[a].isitmine = dlsym(module, "isitmine"); + + info = dlsym(module, "mynameis"); + + plugins[a].module = module; + plugins[a].whoami = a; + plugins[a].file = file; + plugins[a].myname = (char *) info(); + plugins[a].active = 1; + } + return a; +} + /* =========================== close a plugin ===============================*/ + +/* +int close_plugin( int a) +{ + char report[255]; + + if(dlclose(plugins[a].module)) { + sprintf(report, "Error while unloading %s", plugins[a].myname); + plugins[a].displaying = 1; + return -1; + } + else { + sprintf(report, "Successfully unloaded %s", plugins[a].myname); + plugins[a].displaying = 0; + return 0; + } + xosd_display(settings.myosd, 0, XOSD_string, report); + xosd_display(settings.myosd, 1, XOSD_string, ""); +} +*/ + + +/*============================ display_stuff()=============================== */ +void display_stuff(char command[BUFSIZ], char arguments[BUFSIZ]) +{ + char c; + char arg_first[BUFSIZ]; + char arg_secound[BUFSIZ]; + int a,i; + + sprintf(arg_first, ""); + sprintf(arg_secound, ""); + + /* separate the arguments in sub_arguments .... or not?*/ + i=0; + a=0; + while ((c=arguments[i])!=','&&c!='\n'&&c!='\0') { + if (c=='\\') { + i++; + arg_first[a] = arguments[i]; + } + else { + arg_first[a] = c; + } + a++; + i++; + } + arg_first[a] = '\0'; + i++; + a = 0; + + while((c=arguments[i])!='\n'&&c!='\0'&&c!=')') { + if (c=='\\') { + i++; + arg_secound[a] = arguments[i]; + } + else { + arg_secound[a] = c; + } + a++; + i++; + } + arg_secound[a] = '\0'; + + /* done with the arguments */ + + if (strcmp(command, "load")==0) { + +/* + for(i=0;i<n+1;i++) { + if(strcmp(arg_first, plugins[i].myname)==0) { + strcpy(arg_secound, plugins[i].file); + } + } + + a = load_plugin( arg_secound); + +*/ a = load_plugin( arg_first ); + sprintf(arg_secound, "Error loading %s", arg_first); + + if(a>=0) { + if(a>n&&a<MAX_PLUGINS) + n=a; + if(plugins[a].isitmine("stop", NULL, NULL)) { + sprintf(arg_secound, "Successfully loaded %s", plugins[a].myname); + } + } + + xosd_display(settings.myosd, 0, XOSD_string, arg_secound); + xosd_display(settings.myosd, 1, XOSD_string, ""); + + } + else if (strcmp(command, "strn")==0) { + xosd_display(settings.myosd, 0, XOSD_string, arg_first); + xosd_display(settings.myosd, 1, XOSD_string, arg_secound); + } + else if (strcmp(command, "bars")==0) { + xosd_display(settings.myosd, 0, XOSD_string, arg_first); + xosd_display(settings.myosd, 1, XOSD_percentage, atoi(arg_secound)); + } + else if (strcmp(command, "slid")==0) { + xosd_display(settings.myosd, 0, XOSD_string, arg_first); + xosd_display(settings.myosd, 1, XOSD_slider, atoi(arg_secound)); + } + else if (strcmp(command, "dset")==0) { + control_options(&settings, arg_first, arg_secound); + } + else if (strcmp(command, "exit")==0) { + xosd_display(settings.myosd, 0, XOSD_string, "Goodbye"); + xosd_display(settings.myosd, 1, XOSD_string, ""); + for(i=0;i<n+1;i++) { + if(plugins[i].active) { + plugins[i].isitmine("stop", NULL, NULL); + } + } + sleep(2); + settings.displaying = 0; + } + else { + i = 0; + a = 0; + while(i==0&&a<MAX_PLUGINS) { + if(plugins[a].active) { + i = plugins[a].isitmine(command, arg_first, arg_secound); + } + a++; + } + if(i==0) { + xosd_display(settings.myosd, 0, XOSD_string, command); + xosd_display(settings.myosd, 1, XOSD_string, "No such command"); + } + } +} + +/*================================control_sh() ============================= */ +void *control_sh(void *arg) +{ + int a,i; + char c; + char command[BUFSIZ]; + char command_arg[BUFSIZ]; + + char fifo_file[PATH_MAX +1]; + + FILE *fp; + char readbuf[BUFSIZ]; + + sprintf(fifo_file, "%s.%d",OSD_FIFO_PATH, getuid()); + settings.displaying = 1; + /* we open the osd*/ + settings.myosd = xosd_create (2); + + initialize_osd(&settings); + load_basic_plugins(); + + /* create the fifo file*/ + unlink(fifo_file); + umask(0); + mknod(fifo_file, S_IFIFO|0600, 0); + /*open and read the fifo*/ + while (settings.displaying) { + fp = fopen(fifo_file, "r"); + /*Read the bufer and check that it's not a comment*/ + while(fgets(readbuf, BUFSIZ, fp)) { + + if (readbuf[c]=='#') continue; + + /*ignore spaces*/ + for (i=0; i<BUFSIZ&&((c=readbuf[i])==' '||c=='\t'); i++); + /*get the command*/ + for (a=0; (c=readbuf[i])!='\n'&&c!='('; a++,i++) + command[a] = readbuf[i]; + command[a] = '\0'; + /*get the command's arguments*/ + i ++; + for(a=0; (c=readbuf[i])!='\0'&&c!='\n'&&c!=')';a++,i++) { + if (c=='\\') { + i++; + command_arg[a] = readbuf[i]; + } + else { + command_arg[a]=c; + } + } + command_arg[a] = '\0'; + /*execute the command from the fifo and close it*/ + display_stuff(command, command_arg); + } + fclose(fp); + } + unlink(fifo_file); + sprintf(fifo_file, "%s.pid", fifo_file); + unlink(fifo_file); + xosd_destroy(settings.myosd); + exit(0); +} diff --git a/src/osdsh/mixerwatch.c b/src/osdsh/mixerwatch.c new file mode 100644 index 0000000..025e902 --- /dev/null +++ b/src/osdsh/mixerwatch.c @@ -0,0 +1,161 @@ +#include "osdsh.h" +#include "../config.h" +#define IAM 0 +#define MYNAME "Mixer" + +char mixerdevice[PATH_MAX+1] = MIXER; +int dev; +settings_t mixerset; +int vol[SOUND_MIXER_NRDEVICES]; +int old_vol[SOUND_MIXER_NRDEVICES]; +char *devicelabels[SOUND_MIXER_NRDEVICES]=SOUND_DEVICE_LABELS; + +void *mixer_watch(void *arg); + +/* ==================== REQUIERED FOR PLUGINS ============================== + +***** ID of the plugin, contact me before you asign this to your plugin!! ***** +*/ +int whoami(void) { + return IAM; +} + +/* Return a pointer to the name of the plugin */ +char *mynameis() { + char *a = MYNAME; + return a; +} + +/* This function sets the default (initial) values for our osd + Here i just load the default values, but you can load + your own in your plugin. +*/ +void initialize_myosd() { + set_defaults(&mixerset); +} + +/* This function takes a command and arguments, if the command is ours, execute + it and return 1, if not, return 0*/ + +int isitmine( char command[BUFSIZ], char arg_first[BUFSIZ], + char arg_secound[BUFSIZ]) +{ + int i=1; + + if(strcmp(command, "stop")==0) { + mixerset.displaying = 0; + } + else if(strcmp(command, "start")==0) { + if(!mixerset.displaying) { + mixerset.displaying = 1; + pthread_create(&mixerset.mythread, NULL, mixer_watch, NULL); + } + } + else if (strcmp(command, "smix")==0) { + control_options(&mixerset, arg_first, arg_secound); + } + else if (strcmp(command, "mixr")==0) { + if (atoi(arg_first)) { + isitmine("start", NULL, NULL); + } + else { + mixerset.displaying = 0; + } + } + else { + i = 0; + } + return i; +} + + + + +/*The next functions were taken from osdd-0.0.2, +written by W. Michael Petullo <osdd@flyn.org>, with some ideas, and slightly +(one or two chars) modified by me*/ + +/* ============================ initialize_vols () ========================= */ +void initialize_vols( int devmask) +{ + int i; + int volume; + for (i=0;i<SOUND_MIXER_NRDEVICES;i++) { + if (devmask & (1 << i)) { + if (ioctl(dev, MIXER_READ(i), &volume) == -1) { + perror(mixerdevice); + mixerset.displaying=0; + } + old_vol[i] = vol[i] = volume; + } + } +} + +/* ============================ display_channel () ========================= */ +void display_channel(int channel) +{ + char channel_name[BUFSIZ]; + if (!channel) + sprintf(channel_name, "Master Volume"); + else + sprintf(channel_name, "%s Volume", devicelabels[channel]); + + if (ioctl(dev, MIXER_READ(channel), &vol[channel]) == -1) { + perror(mixerdevice); + mixerset.displaying = 0; + } + /*if muted, we say it!!*/ + if (!(vol[0] & 0xff || (vol[0] >> 8) & 0xff)) { + xosd_display(mixerset.myosd, mixerset.position, XOSD_bottom, "Muted"); + xosd_display(mixerset.myosd, !mixerset.position, XOSD_bottom, ""); + } + /* not muted, so lets check if the vol changed, if so, display + them, if not, just ignore it*/ + else if (vol[channel] != old_vol[channel]) { + xosd_display(mixerset.myosd, 0, XOSD_string, channel_name); + xosd_display(mixerset.myosd, 1, XOSD_percentage, + (((vol[channel]>>8)&0xff)+vol[channel]&0xff)/2); + } +} + +/*================================= mixer_watch() ============================*/ +void *mixer_watch(void *arg) +{ + int devmask; + int i; + /* we open the osd for the mixer*/ + /* Mixer usually goes on the bottom of the screen... so*/ + + mixerset.position = XOSD_bottom; + + mixerset.myosd = xosd_create(2); + initialize_osd(&mixerset); + + /*open the mixer device for reading*/ + + if ((dev = open(mixerdevice, O_RDWR)) < 0) { + perror("Error opening"); + perror(mixerdevice); + pthread_exit(0); + } + if (ioctl(dev, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) { + perror("Error reading"); + perror(mixerdevice); + pthread_exit(0); + } + /*initialize the volume.....*/ + initialize_vols(devmask); + + while(mixerset.displaying) { + for (i=0;i<SOUND_MIXER_NRDEVICES;i++) { + if (devmask & (1 << i)) { + display_channel(i); + old_vol[i] = vol[i]; + } + } + usleep(1); + } + xosd_destroy(mixerset.myosd); + pthread_exit(0); +} + diff --git a/src/osdsh/osdsh.c b/src/osdsh/osdsh.c new file mode 100644 index 0000000..d4989b6 --- /dev/null +++ b/src/osdsh/osdsh.c @@ -0,0 +1,175 @@ +#include "osdsh.h" +#include "../config.h" + + +/* ==============================global variables=============================*/ +/* +messages_t messages; +*/ + +/*basic setup here*/ + +extern settings_t settings; +/* +extern settings_t mixerset; +extern settings_t clockset; +extern settings_t pppset; +extern settings_t apmset; + +void *apm_watch(void *arg); +void *control_sh(void *arg); +void *mixer_watch(void *arg); +void *connection_watch(void *arg); +void *clock_display(void *arg); +*/ + +/* ============================ usage () =================================== */ +void usage(const int exitcode, const char *error, const char *more) +{ + fprintf(stderr, "osdsh %s\n", VERSION); + fprintf(stderr, "usage: osdsh [options]\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " -h display usage\n"); + fprintf(stderr, " -m mixer set mixer %s\n", MIXER); + fprintf(stderr, " -f font set font %s \n", FONT); + fprintf(stderr, " -c color set color %s \n", COLOR); + fprintf(stderr, " -d int set OSD delay %d \n", TIMEOUT); + fprintf(stderr, " -o int set Shadow Offset %d \n", SHADOW_OFFSET); + fprintf(stderr, " -p <0|1> position of the osd, 0 for bottom,\n"); + fprintf(stderr, " 1 for top. Default 1 (top).\n"); + fprintf(stderr, " -a <0|1|2> align of the osd. left,center or right.\n"); + fprintf(stderr, " -n number set the nice number so osdsh won't eat your cpu\n"); + fprintf(stderr, "\n"); + if (error) + fprintf(stderr, "%s: %s\n\n", error, more); + exit(exitcode); +} + + + +/* ============================ parse_args () ============================== */ +void parse_args(int argc, char *argv[], settings_t * settings) +{ + char c; + int opt_index = 0; + struct option opts[] = { + {"help", 0, 0, 'h'}, + {"position", 1, 0, 'p'}, + {"soffset", 1, 0, 'o'}, + {"mixer", 1, 0, 'm'}, + {"font", 1, 0, 'f'}, + {"color", 1, 0, 'c'}, + {"delay", 1, 0, 'd'}, + {"align", 1, 0, 'a'}, + {"nice", 1, 0, 'n'} + }; + while ((c = getopt_long(argc, argv, "hm:f:c:p:d:o:n:", opts, &opt_index)) >= 0) { + switch (c) { + case 'h': + usage(0, NULL, NULL); + exit(0); + case 'f': + strncpy(settings->font, optarg, BUFSIZ); + settings->font[BUFSIZ] = '\0'; + break; + case 'c': + strncpy(settings->color, optarg, BUFSIZ); + settings->color[BUFSIZ] = '\0'; + break; + case 'p': + settings->position = atoi(optarg); + break; + case 'a': + settings->align = atoi(optarg); + break; + case 'd': + settings->delay = atoi(optarg); + break; +/* + case 'm': + strncpy(messages.mixerdevice, optarg, BUFSIZ); + messages.mixerdevice[PATH_MAX+1] = '\0'; + break; +*/ + case 'o': + settings->soffset = atoi(optarg); + break; + case 'n': + nice(atoi(optarg)); + break; + default: + usage(1, NULL, NULL); + exit(1); + } + } +} + +void load_basic_plugins(void) { + int a; + char file[PATH_MAX+255]; + + sprintf(file, "%s/libosdshmixer.so", PLUGINSDIR); + a = load_plugin(file); + if (a<0) { + xosd_display(settings.myosd, 0, XOSD_string, "No Mixer Support"); + xosd_display(settings.myosd, 1, XOSD_string, ""); + } + + sprintf(file, "%s/libosdshclock.so", PLUGINSDIR); + a = load_plugin(file); + if (a<0) { + xosd_display(settings.myosd, 0, XOSD_string, "No Clock Support"); + xosd_display(settings.myosd, 1, XOSD_string, ""); + } + + sprintf(file, "%s/libosdshnet.so", PLUGINSDIR); + a = load_plugin(file); + if (a<0) { + xosd_display(settings.myosd, 0, XOSD_string, "No Net Support"); + xosd_display(settings.myosd, 1, XOSD_string, ""); + } + + sprintf(file, "%s/libosdshapm.so", PLUGINSDIR); + a = load_plugin(file); + if (a<0) { + xosd_display(settings.myosd, 0, XOSD_string, "No APM/Battery support"); + xosd_display(settings.myosd, 1, XOSD_string, ""); + } +} + +/* ============================ main () ==================================== */ + +int main(int argc, char *argv[], char *env[]) +{ + pid_t childpid; + + char pid_file[PATH_MAX+1]; + FILE *fp; + + set_defaults(&settings); + initialize_osd(&settings); + + parse_args(argc, argv, &settings); +/* +#ifndef NOAPM + apmset = settings; +#endif + pppset = mixerset = settings; +*/ + + if((childpid=fork())<0) { + perror("fork"); + exit(1); + } + if (childpid==0) { + control_sh(NULL); + } + else { + sprintf(pid_file, "%s.%d.pid", OSD_FIFO_PATH, getuid()) ; + fp=fopen(pid_file, "w"); + fprintf(fp, "%d", childpid); + fclose(fp); + exit(0); + } + return(0); +} diff --git a/src/osdsh/osdsh.h b/src/osdsh/osdsh.h new file mode 100644 index 0000000..d653252 --- /dev/null +++ b/src/osdsh/osdsh.h @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <getopt.h> +#include <string.h> +#include <ctype.h> +#include <fcntl.h> +#include <pthread.h> +#include <dlfcn.h> + +#include <linux/limits.h> +#include <linux/stat.h> +#include <linux/soundcard.h> + +#include <xosd.h> + +/*============================== settings_t ==================================*/ + +typedef struct settings_t { + xosd *myosd; + char font[BUFSIZ + 1]; + char color[BUFSIZ + 1]; + int soffset; + int xoffset; + int yoffset; + xosd_align align; + xosd_pos position; + int displaying; + int delay; + pthread_t mythread; +} settings_t; + +typedef struct plugininfo_t { + int whoami; + int active; + void *module; + char *file; + char *myname; + int (*isitmine)(); +} plugininfo_t; + diff --git a/src/osdsh/utils.c b/src/osdsh/utils.c new file mode 100644 index 0000000..024b6bf --- /dev/null +++ b/src/osdsh/utils.c @@ -0,0 +1,97 @@ +#include "osdsh.h" +#include "../config.h" + +/*This function is used to control the options of the individual osd's*/ + +void control_options(settings_t *setts, char option[2], char argument[BUFSIZ]) +{ + /*this function reads the option to change on each display, changes it + and saves the changes on the corresponding settings structure*/ + + switch (option[0]) { + case 'f': + strncpy(setts->font, argument, BUFSIZ); + if (setts->displaying&&xosd_set_font(setts->myosd, argument)) + fprintf(stderr, "Couldn't change font\n"); + break; + case 'C': + strncpy(setts->color, argument, BUFSIZ); + if (setts->displaying&&xosd_set_colour(setts->myosd, argument)) + fprintf(stderr, "Couldn't change color\n"); + break; + case 'd': + setts->delay = atoi(argument); + if (setts->displaying&&xosd_set_timeout(setts->myosd, atoi(argument))) + fprintf(stderr, "Couldn't change timeout\n"); + break; + case 'b': + setts->position = XOSD_bottom; + if (setts->displaying&&xosd_set_pos(setts->myosd, XOSD_bottom)) + fprintf(stderr, "Couldn't change position\n"); + break; + case 't': + setts->position = XOSD_top; + if (setts->displaying&&xosd_set_pos(setts->myosd, XOSD_top)) + fprintf(stderr, "Couldn't change position\n"); + break; + case 'l': + setts->align = XOSD_left; + if (setts->displaying&&xosd_set_align(setts->myosd, XOSD_left)) + fprintf(stderr, "Couldn't change align\n"); + break; + case 'r': + setts->align = XOSD_right; + if (setts->displaying&&xosd_set_align(setts->myosd, XOSD_right)) + fprintf(stderr, "Couldn't change align\n"); + break; + case 'c': + setts->align = XOSD_center; + if (setts->displaying&&xosd_set_align(setts->myosd, XOSD_center)) + fprintf(stderr, "Couldn't change align\n"); + case 'o': + setts->soffset = atoi(argument); + if (setts->displaying&&xosd_set_shadow_offset(setts->myosd, setts->soffset)) + fprintf(stderr, "Couldn't change Shadow Offset\n"); + break; + case 'y': + setts->yoffset = atoi(argument); + if (setts->displaying&&xosd_set_vertical_offset(setts->myosd, setts->yoffset)) + fprintf(stderr, "Couldn't change vertical offset\n"); + break; + case 'x': + setts->xoffset = atoi(argument); + if (setts->displaying&&xosd_set_horizontal_offset(setts->myosd, setts->xoffset)) + fprintf(stderr, "Couldn't change horizontal offset\n"); + default: + break; + } +} + +/*============================= initialize_osd() =========================== */ +void initialize_osd( settings_t *setts) +{ + xosd_set_font(setts->myosd, setts->font); + xosd_set_colour(setts->myosd, setts->color); + xosd_set_pos(setts->myosd, setts->position); + xosd_set_align(setts->myosd, setts->align); + xosd_set_horizontal_offset(setts->myosd, setts->xoffset); + xosd_set_vertical_offset(setts->myosd, setts->yoffset); + xosd_set_shadow_offset(setts->myosd, setts->soffset); + xosd_set_timeout(setts->myosd, setts->delay); +} +/* ============================ set_defaults () ============================ */ +void set_defaults(settings_t *setts) +{ + strncpy(setts->font, FONT, BUFSIZ); + setts->font[BUFSIZ] = '\0'; + strncpy(setts->color, COLOR, BUFSIZ); + setts->color[BUFSIZ] = '\0'; + setts->soffset = SHADOW_OFFSET; + setts->yoffset = DEFAULT_OFFSET; + setts->xoffset = DEFAULT_OFFSET; + setts->align= OSD_ALIGNMENT; + setts->position = OSD_POSITION; + setts->delay = TIMEOUT; + setts->displaying = 0; +} + |