void init_keyevents(void) { char *home = NULL; char *confhome = NULL; char *confpath = NULL; char line[128]; char action[32], k1[32], k2[32], k3[32]; struct __fehkey *cur_kb = NULL; FILE *conf = NULL; int read = 0; memset(&keys, 0, sizeof(keys)); feh_set_kb(&keys.menu_close, 0, XK_Escape , 0, 0 , 0, 0); feh_set_kb(&keys.menu_parent,0, XK_Left , 0, 0 , 0, 0); feh_set_kb(&keys.menu_down , 0, XK_Down , 0, 0 , 0, 0); feh_set_kb(&keys.menu_up , 0, XK_Up , 0, 0 , 0, 0); feh_set_kb(&keys.menu_child, 0, XK_Right , 0, 0 , 0, 0); feh_set_kb(&keys.menu_select,0, XK_Return , 0, XK_space , 0, 0); feh_set_kb(&keys.scroll_left,0, XK_KP_Left , 4, XK_Left , 0, 0); feh_set_kb(&keys.scroll_right,0,XK_KP_Right , 4, XK_Right , 0, 0); feh_set_kb(&keys.scroll_down,0, XK_KP_Down , 4, XK_Down , 0, 0); feh_set_kb(&keys.scroll_up , 0, XK_KP_Up , 4, XK_Up , 0, 0); feh_set_kb(&keys.scroll_left_page , 8, XK_Left , 0, 0 , 0, 0); feh_set_kb(&keys.scroll_right_page, 8, XK_Right, 0, 0 , 0, 0); feh_set_kb(&keys.scroll_down_page , 8, XK_Down , 0, 0 , 0, 0); feh_set_kb(&keys.scroll_up_page , 8, XK_Up , 0, 0 , 0, 0); feh_set_kb(&keys.prev_img , 0, XK_Left , 0, XK_p , 0, XK_BackSpace); feh_set_kb(&keys.next_img , 0, XK_Right , 0, XK_n , 0, XK_space); feh_set_kb(&keys.jump_back , 0, XK_Page_Up , 0, XK_KP_Page_Up, 0, 0); feh_set_kb(&keys.jump_fwd , 0, XK_Page_Down , 0, XK_KP_Page_Down,0,0); feh_set_kb(&keys.jump_random,0, XK_z , 0, 0 , 0, 0); feh_set_kb(&keys.quit , 0, XK_Escape , 0, XK_q , 0, 0); feh_set_kb(&keys.close , 0, XK_x , 0, 0 , 0, 0); feh_set_kb(&keys.remove , 0, XK_Delete , 0, 0 , 0, 0); feh_set_kb(&keys.delete , 4, XK_Delete , 0, 0 , 0, 0); feh_set_kb(&keys.jump_first, 0, XK_Home , 0, XK_KP_Home , 0, 0); feh_set_kb(&keys.jump_last , 0, XK_End , 0, XK_KP_End , 0, 0); feh_set_kb(&keys.action_0 , 0, XK_Return , 0, XK_0 , 0, XK_KP_0); feh_set_kb(&keys.action_1 , 0, XK_1 , 0, XK_KP_1 , 0, 0); feh_set_kb(&keys.action_2 , 0, XK_2 , 0, XK_KP_2 , 0, 0); feh_set_kb(&keys.action_3 , 0, XK_3 , 0, XK_KP_3 , 0, 0); feh_set_kb(&keys.action_4 , 0, XK_4 , 0, XK_KP_4 , 0, 0); feh_set_kb(&keys.action_5 , 0, XK_5 , 0, XK_KP_5 , 0, 0); feh_set_kb(&keys.action_6 , 0, XK_6 , 0, XK_KP_6 , 0, 0); feh_set_kb(&keys.action_7 , 0, XK_7 , 0, XK_KP_7 , 0, 0); feh_set_kb(&keys.action_8 , 0, XK_8 , 0, XK_KP_8 , 0, 0); feh_set_kb(&keys.action_9 , 0, XK_9 , 0, XK_KP_9 , 0, 0); feh_set_kb(&keys.zoom_in , 0, XK_Up , 0, XK_KP_Add , 0, 0); feh_set_kb(&keys.zoom_out , 0, XK_Down , 0, XK_KP_Subtract,0, 0); feh_set_kb(&keys.zoom_default, 0, XK_KP_Multiply, 0, XK_asterisk, 0, 0); feh_set_kb(&keys.zoom_fit , 0, XK_KP_Divide , 0, XK_slash , 0, 0); feh_set_kb(&keys.size_to_image, 0, XK_w , 0, 0 , 0, 0); feh_set_kb(&keys.render , 0, XK_KP_Begin , 0, XK_R , 0, 0); feh_set_kb(&keys.toggle_actions, 0, XK_a, 0, 0, 0, 0); feh_set_kb(&keys.toggle_aliasing, 0, XK_A, 0, 0, 0, 0); feh_set_kb(&keys.toggle_filenames, 0, XK_d, 0, 0, 0, 0); #ifdef HAVE_LIBEXIF feh_set_kb(&keys.toggle_exif, 0, XK_e, 0, 0, 0, 0); #endif feh_set_kb(&keys.toggle_info, 0, XK_i, 0, 0, 0, 0); feh_set_kb(&keys.toggle_pointer, 0, XK_o, 0, 0, 0, 0); feh_set_kb(&keys.toggle_caption, 0, XK_c, 0, 0, 0, 0); feh_set_kb(&keys.toggle_pause, 0, XK_h, 0, 0, 0, 0); feh_set_kb(&keys.toggle_menu, 0, XK_m, 0, 0, 0, 0); feh_set_kb(&keys.toggle_fullscreen, 0, XK_v, 0, 0, 0, 0); feh_set_kb(&keys.reload_image, 0, XK_r, 0, 0, 0, 0); feh_set_kb(&keys.save_image, 0, XK_s, 0, 0, 0, 0); feh_set_kb(&keys.save_filelist, 0, XK_f, 0, 0, 0, 0); feh_set_kb(&keys.orient_1, 0, XK_greater, 0, 0, 0, 0); feh_set_kb(&keys.orient_3, 0, XK_less, 0, 0, 0, 0); feh_set_kb(&keys.flip, 0, XK_underscore, 0, 0, 0, 0); feh_set_kb(&keys.mirror, 0, XK_bar, 0, 0, 0, 0); feh_set_kb(&keys.reload_minus, 0, XK_minus, 0, 0, 0, 0); feh_set_kb(&keys.reload_plus, 0, XK_plus, 0, 0, 0, 0); feh_set_kb(&keys.toggle_keep_vp, 0, XK_k, 0, 0, 0, 0); home = getenv("HOME"); confhome = getenv("XDG_CONFIG_HOME"); if (confhome) confpath = estrjoin("/", confhome, "feh/keys", NULL); else if (home) confpath = estrjoin("/", home, ".config/feh/keys", NULL); else return; conf = fopen(confpath, "r"); free(confpath); if (!conf && ((conf = fopen("/etc/feh/keys", "r")) == NULL)) return; while (fgets(line, sizeof(line), conf)) { *action = '\0'; *k1 = '\0'; *k2 = '\0'; *k3 = '\0'; read = sscanf(line, "%31s %31s %31s %31s\n", (char *) &action, (char *) &k1, (char* ) &k2, (char *) &k3); if ((read == EOF) || (read == 0) || (line[0] == '#')) continue; if (!strcmp(action, "menu_close")) cur_kb = &keys.menu_close; else if (!strcmp(action, "menu_parent")) cur_kb = &keys.menu_parent; else if (!strcmp(action, "menu_down")) cur_kb = &keys.menu_down; else if (!strcmp(action, "menu_up")) cur_kb = &keys.menu_up; else if (!strcmp(action, "menu_child")) cur_kb = &keys.menu_child; else if (!strcmp(action, "menu_select")) cur_kb = &keys.menu_select; else if (!strcmp(action, "scroll_right")) cur_kb = &keys.scroll_right; else if (!strcmp(action, "scroll_left")) cur_kb = &keys.scroll_left; else if (!strcmp(action, "scroll_up")) cur_kb = &keys.scroll_up; else if (!strcmp(action, "scroll_down")) cur_kb = &keys.scroll_down; else if (!strcmp(action, "scroll_right_page")) cur_kb = &keys.scroll_right_page; else if (!strcmp(action, "scroll_left_page")) cur_kb = &keys.scroll_left_page; else if (!strcmp(action, "scroll_up_page")) cur_kb = &keys.scroll_up_page; else if (!strcmp(action, "scroll_down_page")) cur_kb = &keys.scroll_down_page; else if (!strcmp(action, "prev_img")) cur_kb = &keys.prev_img; else if (!strcmp(action, "next_img")) cur_kb = &keys.next_img; else if (!strcmp(action, "jump_back")) cur_kb = &keys.jump_back; else if (!strcmp(action, "jump_fwd")) cur_kb = &keys.jump_fwd; else if (!strcmp(action, "jump_random")) cur_kb = &keys.jump_random; else if (!strcmp(action, "quit")) cur_kb = &keys.quit; else if (!strcmp(action, "close")) cur_kb = &keys.close; else if (!strcmp(action, "remove")) cur_kb = &keys.remove; else if (!strcmp(action, "delete")) cur_kb = &keys.delete; else if (!strcmp(action, "jump_first")) cur_kb = &keys.jump_first; else if (!strcmp(action, "jump_last")) cur_kb = &keys.jump_last; else if (!strcmp(action, "action_0")) cur_kb = &keys.action_0; else if (!strcmp(action, "action_1")) cur_kb = &keys.action_1; else if (!strcmp(action, "action_2")) cur_kb = &keys.action_2; else if (!strcmp(action, "action_3")) cur_kb = &keys.action_3; else if (!strcmp(action, "action_4")) cur_kb = &keys.action_4; else if (!strcmp(action, "action_5")) cur_kb = &keys.action_5; else if (!strcmp(action, "action_6")) cur_kb = &keys.action_6; else if (!strcmp(action, "action_7")) cur_kb = &keys.action_7; else if (!strcmp(action, "action_8")) cur_kb = &keys.action_8; else if (!strcmp(action, "action_9")) cur_kb = &keys.action_9; else if (!strcmp(action, "zoom_in")) cur_kb = &keys.zoom_in; else if (!strcmp(action, "zoom_out")) cur_kb = &keys.zoom_out; else if (!strcmp(action, "zoom_default")) cur_kb = &keys.zoom_default; else if (!strcmp(action, "zoom_fit")) cur_kb = &keys.zoom_fit; else if (!strcmp(action, "size_to_image")) cur_kb = &keys.size_to_image; else if (!strcmp(action, "render")) cur_kb = &keys.render; else if (!strcmp(action, "toggle_actions")) cur_kb = &keys.toggle_actions; else if (!strcmp(action, "toggle_aliasing")) cur_kb = &keys.toggle_aliasing; else if (!strcmp(action, "toggle_filenames")) cur_kb = &keys.toggle_filenames; #ifdef HAVE_LIBEXIF else if (!strcmp(action, "toggle_exif")) cur_kb = &keys.toggle_exif; #endif else if (!strcmp(action, "toggle_info")) cur_kb = &keys.toggle_info; else if (!strcmp(action, "toggle_pointer")) cur_kb = &keys.toggle_pointer; else if (!strcmp(action, "toggle_caption")) cur_kb = &keys.toggle_caption; else if (!strcmp(action, "toggle_pause")) cur_kb = &keys.toggle_pause; else if (!strcmp(action, "toggle_menu")) cur_kb = &keys.toggle_menu; else if (!strcmp(action, "toggle_fullscreen")) cur_kb = &keys.toggle_fullscreen; else if (!strcmp(action, "reload_image")) cur_kb = &keys.reload_image; else if (!strcmp(action, "save_image")) cur_kb = &keys.save_image; else if (!strcmp(action, "save_filelist")) cur_kb = &keys.save_filelist; else if (!strcmp(action, "orient_1")) cur_kb = &keys.orient_1; else if (!strcmp(action, "orient_3")) cur_kb = &keys.orient_3; else if (!strcmp(action, "flip")) cur_kb = &keys.flip; else if (!strcmp(action, "mirror")) cur_kb = &keys.mirror; else if (!strcmp(action, "reload_minus")) cur_kb = &keys.reload_minus; else if (!strcmp(action, "reload_plus")) cur_kb = &keys.reload_plus; else if (!strcmp(action, "toggle_keep_vp")) cur_kb = &keys.toggle_keep_vp; else weprintf("keys: Invalid action: %s", action); if (cur_kb) { feh_set_parse_kb_partial(cur_kb, 0, k1); feh_set_parse_kb_partial(cur_kb, 1, k2); feh_set_parse_kb_partial(cur_kb, 2, k3); } }
void init_keyevents(void) { char *home = NULL; char *confhome = NULL; char *confpath = NULL; char line[128]; char action[32], k1[32], k2[32], k3[32]; fehkey *cur_kb = NULL; FILE *conf = NULL; int read = 0; /* * The feh_set_kb statements must have the same order as the key_action * enum. */ feh_set_kb("menu_close" , 0, XK_Escape , 0, 0 , 0, 0); feh_set_kb("menu_parent", 0, XK_Left , 0, 0 , 0, 0); feh_set_kb("menu_down", 0, XK_Down , 0, 0 , 0, 0); feh_set_kb("menu_up", 0, XK_Up , 0, 0 , 0, 0); feh_set_kb("menu_child", 0, XK_Right , 0, 0 , 0, 0); feh_set_kb("menu_select", 0, XK_Return , 0, XK_space , 0, 0); feh_set_kb("scroll_left",0, XK_KP_Left , 4, XK_Left , 0, 0); feh_set_kb("scroll_right", 0,XK_KP_Right , 4, XK_Right , 0, 0); feh_set_kb("scroll_down",0, XK_KP_Down , 4, XK_Down , 0, 0); feh_set_kb("scroll_up", 0, XK_KP_Up , 4, XK_Up , 0, 0); feh_set_kb("scroll_left_page" , 8, XK_Left , 0, 0 , 0, 0); feh_set_kb("scroll_right_page", 8, XK_Right, 0, 0 , 0, 0); feh_set_kb("scroll_down_page" , 8, XK_Down , 0, 0 , 0, 0); feh_set_kb("scroll_up_page" , 8, XK_Up , 0, 0 , 0, 0); feh_set_kb("prev_img" , 0, XK_Left , 0, XK_p , 0, XK_BackSpace); feh_set_kb("next_img" , 0, XK_Right , 0, XK_n , 0, XK_space); feh_set_kb("jump_back" , 0, XK_Page_Up , 0, XK_KP_Page_Up, 0, 0); feh_set_kb("jump_fwd" , 0, XK_Page_Down , 0, XK_KP_Page_Down,0,0); feh_set_kb("prev_dir" , 0, XK_bracketleft, 0, 0 , 0, 0); feh_set_kb("next_dir" , 0, XK_bracketright, 0, 0 , 0, 0); feh_set_kb("jump_random" ,0, XK_z , 0, 0 , 0, 0); feh_set_kb("quit" , 0, XK_Escape , 0, XK_q , 0, 0); feh_set_kb("close" , 0, XK_x , 0, 0 , 0, 0); feh_set_kb("remove" , 0, XK_Delete , 0, 0 , 0, 0); feh_set_kb("delete" , 4, XK_Delete , 0, 0 , 0, 0); feh_set_kb("jump_first" , 0, XK_Home , 0, XK_KP_Home , 0, 0); feh_set_kb("jump_last" , 0, XK_End , 0, XK_KP_End , 0, 0); feh_set_kb("action_0" , 0, XK_Return , 0, XK_0 , 0, XK_KP_0); feh_set_kb("action_1" , 0, XK_1 , 0, XK_KP_1 , 0, 0); feh_set_kb("action_2" , 0, XK_2 , 0, XK_KP_2 , 0, 0); feh_set_kb("action_3" , 0, XK_3 , 0, XK_KP_3 , 0, 0); feh_set_kb("action_4" , 0, XK_4 , 0, XK_KP_4 , 0, 0); feh_set_kb("action_5" , 0, XK_5 , 0, XK_KP_5 , 0, 0); feh_set_kb("action_6" , 0, XK_6 , 0, XK_KP_6 , 0, 0); feh_set_kb("action_7" , 0, XK_7 , 0, XK_KP_7 , 0, 0); feh_set_kb("action_8" , 0, XK_8 , 0, XK_KP_8 , 0, 0); feh_set_kb("action_9" , 0, XK_9 , 0, XK_KP_9 , 0, 0); feh_set_kb("zoom_in" , 0, XK_Up , 0, XK_KP_Add , 0, 0); feh_set_kb("zoom_out" , 0, XK_Down , 0, XK_KP_Subtract,0, 0); feh_set_kb("zoom_default" , 0, XK_KP_Multiply, 0, XK_asterisk,0, 0); feh_set_kb("zoom_fit" , 0, XK_KP_Divide , 0, XK_slash , 0, 0); feh_set_kb("zoom_fill" , 0, XK_exclam , 0, 0 , 0, 0); feh_set_kb("size_to_image" , 0, XK_w , 0, 0 , 0, 0); feh_set_kb("render" , 0, XK_KP_Begin , 0, XK_R , 0, 0); feh_set_kb("toggle_actions" , 0, XK_a, 0, 0, 0, 0); feh_set_kb("toggle_aliasing" , 0, XK_A, 0, 0, 0, 0); feh_set_kb("toggle_auto_zoom" , 0, XK_Z, 0, 0, 0, 0); #ifdef HAVE_LIBEXIF feh_set_kb("toggle_exif" , 0, XK_e, 0, 0, 0, 0); #endif feh_set_kb("toggle_filenames" , 0, XK_d, 0, 0, 0, 0); feh_set_kb("toggle_info" , 0, XK_i, 0, 0, 0, 0); feh_set_kb("toggle_pointer" , 0, XK_o, 0, 0, 0, 0); feh_set_kb("toggle_caption" , 0, XK_c, 0, 0, 0, 0); feh_set_kb("toggle_pause" , 0, XK_h, 0, 0, 0, 0); feh_set_kb("toggle_menu" , 0, XK_m, 0, 0, 0, 0); feh_set_kb("toggle_fullscreen" , 0, XK_f, 0, 0, 0, 0); feh_set_kb("reload_image" , 0, XK_r, 0, 0, 0, 0); feh_set_kb("save_image" , 0, XK_s, 0, 0, 0, 0); feh_set_kb("save_filelist" , 0, XK_L, 0, 0, 0, 0); feh_set_kb("orient_1" , 0, XK_greater, 0, 0, 0, 0); feh_set_kb("orient_3" , 0, XK_less, 0, 0, 0, 0); feh_set_kb("flip" , 0, XK_underscore, 0, 0, 0, 0); feh_set_kb("mirror" , 0, XK_bar, 0, 0, 0, 0); feh_set_kb("reload_minus" , 0, XK_minus, 0, 0, 0, 0); feh_set_kb("reload_plus" , 0, XK_plus, 0, 0, 0, 0); feh_set_kb("toggle_keep_vp" , 0, XK_k, 0, 0, 0, 0); feh_set_kb("toggle_fixed_geometry" , 0, XK_g, 0, 0, 0, 0); feh_set_kb("pan" , 0, 0, 0, 0, 0, 0); feh_set_kb("zoom" , 0, 0, 0, 0, 0, 0); feh_set_kb("blur" , 0, 0, 0, 0, 0, 0); feh_set_kb("rotate" , 0, 0, 0, 0, 0, 0); home = getenv("HOME"); confhome = getenv("XDG_CONFIG_HOME"); if (confhome) confpath = estrjoin("/", confhome, "feh/keys", NULL); else if (home) confpath = estrjoin("/", home, ".config/feh/keys", NULL); else return; conf = fopen(confpath, "r"); free(confpath); if (!conf && ((conf = fopen("/etc/feh/keys", "r")) == NULL)) return; while (fgets(line, sizeof(line), conf)) { *action = '\0'; *k1 = '\0'; *k2 = '\0'; *k3 = '\0'; cur_kb = NULL; read = sscanf(line, "%31s %31s %31s %31s\n", (char *) &action, (char *) &k1, (char* ) &k2, (char *) &k3); if ((read == EOF) || (read == 0) || (line[0] == '#')) continue; cur_kb = feh_str_to_kb(action); if (cur_kb) { feh_set_parse_kb_partial(cur_kb, 0, k1); feh_set_parse_kb_partial(cur_kb, 1, k2); feh_set_parse_kb_partial(cur_kb, 2, k3); } else { weprintf("keys: Invalid action: %s", action); } } fclose(conf); }