/* audio volume control for x11 (c) firk 2020-2022 please respect the authorship feel free to use this code for anything */ #include #include #include #include #include "mixer.h" #include "vol-alsa.h" unsigned int volume; unsigned char mute; extern void handle_audio_mute(void) { alsa_volume(8, NULL, &mute); mute = !mute; alsa_volume(4, NULL, &mute); x11_redraw(); } extern void handle_audio_down(void) { alsa_volume(2, &volume, NULL); if(volume>30) volume -= 30; else volume = 0; alsa_volume(1, &volume, NULL); x11_redraw(); } extern void handle_audio_up(void) { alsa_volume(2, &volume, NULL); if(volume<970) volume += 30; else volume = 1000; alsa_volume(1, &volume, NULL); x11_redraw(); } extern void handle_audio_set(unsigned v) { alsa_volume(2, &volume, NULL); volume = (v<1000)?v:1000; alsa_volume(1, &volume, NULL); x11_redraw(); } static void parse_winprops(char const *a, winprops *r) { bzero(r, sizeof(*r)); if(!a || !*a) return; r->o = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->x0 = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->y0 = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->w = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->h = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->bw = atoi(a); } int main(int argc, char * * argv) { winprops wp; wp.o = wp.x0 = wp.y0 = wp.w = wp.h = wp.bw = 0; if(argc==2) parse_winprops(argv[1],&wp); else { if(argc>=2) wp.o = atoi(argv[1]); if(argc>=3) wp.x0 = atoi(argv[2]); if(argc>=4) wp.y0 = atoi(argv[3]); if(argc>=5) wp.w = atoi(argv[4]); if(argc>=6) wp.h = atoi(argv[5]); if(argc>=7) wp.bw = atoi(argv[6]); } x11_init(NULL,&wp); init_key_hooks(); volume = 600; mute = 1; x11_redraw(); alsa_volume(10, &volume, &mute); while(1) x11_event_cycle(1); return 0; }