/* audio volume control for x11 (c) firk 2020-2021 please respect the authorship feel free to use this code for anything */ #include #include #include #include #include "mixer.h" typedef struct { unsigned int keysym; unsigned int keycode; char const * cmd; } t_hotkey; static t_hotkey key_hooks[] = { { XF86XK_AudioMute }, { XF86XK_AudioLowerVolume }, { XF86XK_AudioRaiseVolume } }; #define key_hooks_end (key_hooks+sizeof(key_hooks)/sizeof(*key_hooks)) extern void init_key_hooks(void) { Display * d; Window rootwin; t_hotkey * hk; d = display; rootwin = RootWindowOfScreen(screen); for(hk=key_hooks; hkkeycode = XKeysymToKeycode(d, hk->keysym); if(hk->keycode) XGrabKey(d, hk->keycode, AnyModifier, rootwin, False, GrabModeAsync, GrabModeAsync); } } extern int key_hook_handler(XEvent * ev) { t_hotkey * hk; if(ev->type==KeyPress) { if(!ev->xkey.keycode) return 0; for(hk=key_hooks; hkxkey.keycode==hk->keycode) { switch(hk->keysym) { case XF86XK_AudioMute: handle_audio_mute(); return 1; case XF86XK_AudioLowerVolume: handle_audio_down(); return 1; case XF86XK_AudioRaiseVolume: handle_audio_up(); return 1; } return 1; } } if(ev->type==ButtonPress) { switch(ev->xbutton.button) { case 1: if(ev->xbutton.x>=0) handle_audio_set(ev->xbutton.x); return 1; case 3: handle_audio_mute(); return 1; case 5: case 6: handle_audio_down(); return 1; case 4: case 7: handle_audio_up(); return 1; } } return 0; }