shortcuts.h (1385B)
1 typedef union { 2 int i; 3 unsigned int ui; 4 float f; 5 int vec2i[2]; 6 const void *v; 7 const char *s; 8 } shortcut_arg; 9 10 11 typedef struct { 12 unsigned int mod; 13 KeySym keysym; 14 void (*func)(const shortcut_arg* arg); 15 const shortcut_arg arg; 16 } Shortcut; 17 18 #define shortcuts const Shortcut shortcut_array[] 19 20 #define check_shortcuts(_ksym, _modkey) \ 21 do { \ 22 for (int i = 0; i < LEN(shortcut_array); i++) { \ 23 if (_ksym == shortcut_array[i].keysym && match(shortcut_array[i].mod, _modkey)) { \ 24 shortcut_array[i].func(&(shortcut_array[i].arg)); \ 25 return 1; \ 26 } \ 27 } \ 28 }while(0) 29 30 /* 31 implement with: 32 33 SHORTCUTS() = { 34 // mask keysym function argument 35 { 0, XK_Right, cursor_move_x_relative, {.i = +1} }, 36 { 0, XK_Left, cursor_move_x_relative, {.i = -1} }, 37 { 0, XK_Down, cursor_move_y_relative, {.i = +1} }, 38 }; 39 40 ... 41 42 int 43 keypress_actions(KeySym keysym, int modkey) 44 { 45 check_shortcuts(keysym, modkey); 46 ... 47 */