nsxiv1c68a34
Renamed key/mouse commands to indicate supported modes
+197 −189
3 files changed
| @@ -1,25 +1,29 @@ | |||
| 1 | 1 | #ifdef _WINDOW_CONFIG | |
| 2 | 2 | ||
| 3 | − | /* default window dimensions (overwritten via -g option): */ | |
| 4 | − | enum { WIN_WIDTH = 800, WIN_HEIGHT = 600 }; | |
| 3 | + | /* default window dimensions (overwritten via -g option): */ | |
| 4 | + | enum { | |
| 5 | + | WIN_WIDTH = 800, | |
| 6 | + | WIN_HEIGHT = 600 | |
| 7 | + | }; | |
| 5 | 8 | ||
| 6 | − | /* default color for window background: * | |
| 7 | − | * (see X(7) "COLOR NAMES" section for valid values) */ | |
| 9 | + | /* default color for window background: */ | |
| 8 | 10 | static const char * const BG_COLOR = "#777777"; | |
| 9 | − | /* default color for thumbnail selection: */ | |
| 11 | + | /* default color for thumbnail selection: */ | |
| 10 | 12 | static const char * const SEL_COLOR = "#DDDDDD"; | |
| 13 | + | /* (see X(7) section "COLOR NAMES" for valid values) */ | |
| 11 | 14 | ||
| 12 | 15 | #endif | |
| 13 | 16 | #ifdef _IMAGE_CONFIG | |
| 14 | 17 | ||
| 15 | − | /* how should images be scaled when they are loaded?: * | |
| 16 | − | * (also controllable via -d/-s/-Z/-z options) * | |
| 17 | − | * SCALE_DOWN: 100%, but fit large images into window, * | |
| 18 | − | * SCALE_FIT: fit all images into window, * | |
| 19 | − | * SCALE_ZOOM: use current zoom level, 100% at startup */ | |
| 18 | + | /* how should images be scaled when they are loaded? | |
| 19 | + | * (also controllable via -d/-s/-Z/-z options) | |
| 20 | + | * SCALE_DOWN: 100%, but fit large images into window, | |
| 21 | + | * SCALE_FIT: fit all images into window, | |
| 22 | + | * SCALE_ZOOM: use current zoom level, 100% at startup | |
| 23 | + | */ | |
| 20 | 24 | static const scalemode_t SCALE_MODE = SCALE_DOWN; | |
| 21 | 25 | ||
| 22 | − | /* levels (percent) to use when zooming via '-' and '+': */ | |
| 26 | + | /* levels (percent) to use when zooming via '-' and '+': */ | |
| 23 | 27 | static const float zoom_levels[] = { | |
| 24 | 28 | 12.5, 25.0, 50.0, 75.0, | |
| 25 | 29 | 100.0, 150.0, 200.0, 400.0, 800.0 | |
| @@ -28,92 +32,92 @@ static const float zoom_levels[] = { | |||
| 28 | 32 | #endif | |
| 29 | 33 | #ifdef _THUMBS_CONFIG | |
| 30 | 34 | ||
| 31 | − | /* default dimension of thumbnails (width == height): */ | |
| 35 | + | /* default dimension of thumbnails (width == height): */ | |
| 32 | 36 | enum { THUMB_SIZE = 60 }; | |
| 33 | 37 | ||
| 34 | 38 | #endif | |
| 35 | 39 | #ifdef _MAPPINGS_CONFIG | |
| 36 | 40 | ||
| 37 | − | /* keyboard mappings for image and thumbnail mode: */ | |
| 41 | + | /* keyboard mappings for image and thumbnail mode: */ | |
| 38 | 42 | static const keymap_t keys[] = { | |
| 39 | − | /* ctrl key function argument */ | |
| 40 | − | { False, XK_q, quit, (arg_t) None }, | |
| 41 | − | { False, XK_r, reload, (arg_t) None }, | |
| 42 | − | { False, XK_f, toggle_fullscreen, (arg_t) None }, | |
| 43 | − | { False, XK_a, toggle_antialias, (arg_t) None }, | |
| 44 | − | { False, XK_A, toggle_alpha, (arg_t) None }, | |
| 45 | − | { False, XK_Return, switch_mode, (arg_t) None }, | |
| 46 | − | ||
| 47 | − | { False, XK_g, first, (arg_t) None }, | |
| 48 | − | { False, XK_G, last, (arg_t) None }, | |
| 49 | − | { False, XK_n, navigate, (arg_t) +1 }, | |
| 50 | − | { False, XK_space, navigate, (arg_t) +1 }, | |
| 51 | − | { False, XK_p, navigate, (arg_t) -1 }, | |
| 52 | − | { False, XK_BackSpace, navigate, (arg_t) -1 }, | |
| 53 | − | { False, XK_bracketright, navigate, (arg_t) +10 }, | |
| 54 | − | { False, XK_bracketleft, navigate, (arg_t) -10 }, | |
| 55 | − | ||
| 56 | − | { False, XK_D, remove_image, (arg_t) None }, | |
| 57 | − | ||
| 58 | − | { False, XK_h, move, (arg_t) DIR_LEFT }, | |
| 59 | − | { False, XK_Left, move, (arg_t) DIR_LEFT }, | |
| 60 | − | { False, XK_j, move, (arg_t) DIR_DOWN }, | |
| 61 | − | { False, XK_Down, move, (arg_t) DIR_DOWN }, | |
| 62 | − | { False, XK_k, move, (arg_t) DIR_UP }, | |
| 63 | − | { False, XK_Up, move, (arg_t) DIR_UP }, | |
| 64 | − | { False, XK_l, move, (arg_t) DIR_RIGHT }, | |
| 65 | − | { False, XK_Right, move, (arg_t) DIR_RIGHT }, | |
| 66 | − | ||
| 67 | − | { True, XK_h, pan_screen, (arg_t) DIR_LEFT }, | |
| 68 | − | { True, XK_Left, pan_screen, (arg_t) DIR_LEFT }, | |
| 69 | − | { True, XK_j, pan_screen, (arg_t) DIR_DOWN }, | |
| 70 | − | { True, XK_Down, pan_screen, (arg_t) DIR_DOWN }, | |
| 71 | − | { True, XK_k, pan_screen, (arg_t) DIR_UP }, | |
| 72 | − | { True, XK_Up, pan_screen, (arg_t) DIR_UP }, | |
| 73 | − | { True, XK_l, pan_screen, (arg_t) DIR_RIGHT }, | |
| 74 | − | { True, XK_Right, pan_screen, (arg_t) DIR_RIGHT }, | |
| 75 | − | ||
| 76 | − | { False, XK_H, pan_edge, (arg_t) DIR_LEFT }, | |
| 77 | − | { False, XK_J, pan_edge, (arg_t) DIR_DOWN }, | |
| 78 | − | { False, XK_K, pan_edge, (arg_t) DIR_UP }, | |
| 79 | − | { False, XK_L, pan_edge, (arg_t) DIR_RIGHT }, | |
| 80 | − | ||
| 81 | − | { False, XK_plus, zoom, (arg_t) +1 }, | |
| 82 | − | { False, XK_equal, zoom, (arg_t) +1 }, | |
| 83 | − | { False, XK_KP_Add, zoom, (arg_t) +1 }, | |
| 84 | − | { False, XK_minus, zoom, (arg_t) -1 }, | |
| 85 | − | { False, XK_KP_Subtract, zoom, (arg_t) -1 }, | |
| 86 | − | { False, XK_0, zoom, (arg_t) None }, | |
| 87 | − | { False, XK_KP_0, zoom, (arg_t) None }, | |
| 88 | − | { False, XK_w, fit_to_win, (arg_t) None }, | |
| 89 | − | { False, XK_W, fit_to_img, (arg_t) None }, | |
| 90 | − | ||
| 91 | − | { False, XK_less, rotate, (arg_t) DIR_LEFT }, | |
| 92 | − | { False, XK_greater, rotate, (arg_t) DIR_RIGHT }, | |
| 93 | − | ||
| 94 | − | /* open the current image with given program: */ | |
| 95 | − | { True, XK_g, open_with, (arg_t) "gimp" }, | |
| 96 | − | ||
| 97 | − | /* run shell command line on the current file, | |
| 98 | − | * '#' is replaced by filename: */ | |
| 99 | − | { True, XK_less, run_command, (arg_t) "mogrify -rotate -90 #" }, | |
| 100 | − | { True, XK_greater, run_command, (arg_t) "mogrify -rotate +90 #" }, | |
| 101 | − | { True, XK_comma, run_command, (arg_t) "jpegtran -rotate 270 -copy all -outfile # #" }, | |
| 102 | − | { True, XK_period, run_command, (arg_t) "jpegtran -rotate 90 -copy all -outfile # #" }, | |
| 43 | + | /* ctrl key function argument */ | |
| 44 | + | { False, XK_q, it_quit, (arg_t) None }, | |
| 45 | + | { False, XK_Return, it_switch_mode, (arg_t) None }, | |
| 46 | + | { False, XK_f, it_toggle_fullscreen, (arg_t) None }, | |
| 47 | + | ||
| 48 | + | { False, XK_r, it_reload_image, (arg_t) None }, | |
| 49 | + | { False, XK_D, it_remove_image, (arg_t) None }, | |
| 50 | + | ||
| 51 | + | { False, XK_n, i_navigate, (arg_t) +1 }, | |
| 52 | + | { False, XK_space, i_navigate, (arg_t) +1 }, | |
| 53 | + | { False, XK_p, i_navigate, (arg_t) -1 }, | |
| 54 | + | { False, XK_BackSpace, i_navigate, (arg_t) -1 }, | |
| 55 | + | { False, XK_bracketright, i_navigate, (arg_t) +10 }, | |
| 56 | + | { False, XK_bracketleft, i_navigate, (arg_t) -10 }, | |
| 57 | + | { False, XK_g, it_first, (arg_t) None }, | |
| 58 | + | { False, XK_G, it_last, (arg_t) None }, | |
| 59 | + | ||
| 60 | + | { False, XK_h, it_move, (arg_t) DIR_LEFT }, | |
| 61 | + | { False, XK_Left, it_move, (arg_t) DIR_LEFT }, | |
| 62 | + | { False, XK_j, it_move, (arg_t) DIR_DOWN }, | |
| 63 | + | { False, XK_Down, it_move, (arg_t) DIR_DOWN }, | |
| 64 | + | { False, XK_k, it_move, (arg_t) DIR_UP }, | |
| 65 | + | { False, XK_Up, it_move, (arg_t) DIR_UP }, | |
| 66 | + | { False, XK_l, it_move, (arg_t) DIR_RIGHT }, | |
| 67 | + | { False, XK_Right, it_move, (arg_t) DIR_RIGHT }, | |
| 68 | + | ||
| 69 | + | { True, XK_h, i_pan_screen, (arg_t) DIR_LEFT }, | |
| 70 | + | { True, XK_Left, i_pan_screen, (arg_t) DIR_LEFT }, | |
| 71 | + | { True, XK_j, i_pan_screen, (arg_t) DIR_DOWN }, | |
| 72 | + | { True, XK_Down, i_pan_screen, (arg_t) DIR_DOWN }, | |
| 73 | + | { True, XK_k, i_pan_screen, (arg_t) DIR_UP }, | |
| 74 | + | { True, XK_Up, i_pan_screen, (arg_t) DIR_UP }, | |
| 75 | + | { True, XK_l, i_pan_screen, (arg_t) DIR_RIGHT }, | |
| 76 | + | { True, XK_Right, i_pan_screen, (arg_t) DIR_RIGHT }, | |
| 77 | + | ||
| 78 | + | { False, XK_H, i_pan_edge, (arg_t) DIR_LEFT }, | |
| 79 | + | { False, XK_J, i_pan_edge, (arg_t) DIR_DOWN }, | |
| 80 | + | { False, XK_K, i_pan_edge, (arg_t) DIR_UP }, | |
| 81 | + | { False, XK_L, i_pan_edge, (arg_t) DIR_RIGHT }, | |
| 82 | + | ||
| 83 | + | { False, XK_plus, i_zoom, (arg_t) +1 }, | |
| 84 | + | { False, XK_equal, i_zoom, (arg_t) +1 }, | |
| 85 | + | { False, XK_KP_Add, i_zoom, (arg_t) +1 }, | |
| 86 | + | { False, XK_minus, i_zoom, (arg_t) -1 }, | |
| 87 | + | { False, XK_KP_Subtract, i_zoom, (arg_t) -1 }, | |
| 88 | + | { False, XK_0, i_zoom, (arg_t) None }, | |
| 89 | + | { False, XK_KP_0, i_zoom, (arg_t) None }, | |
| 90 | + | { False, XK_w, i_fit_to_win, (arg_t) None }, | |
| 91 | + | { False, XK_W, i_fit_to_img, (arg_t) None }, | |
| 92 | + | ||
| 93 | + | { False, XK_less, i_rotate, (arg_t) DIR_LEFT }, | |
| 94 | + | { False, XK_greater, i_rotate, (arg_t) DIR_RIGHT }, | |
| 95 | + | ||
| 96 | + | { False, XK_a, i_toggle_antialias, (arg_t) None }, | |
| 97 | + | { False, XK_A, i_toggle_alpha, (arg_t) None }, | |
| 98 | + | ||
| 99 | + | /* open current image with given program: */ | |
| 100 | + | { True, XK_g, it_open_with, (arg_t) "gimp" }, | |
| 101 | + | ||
| 102 | + | /* run shell command line on current file ('#' is replaced by file path: */ | |
| 103 | + | { True, XK_less, it_shell_cmd, (arg_t) "mogrify -rotate -90 #" }, | |
| 104 | + | { True, XK_greater, it_shell_cmd, (arg_t) "mogrify -rotate +90 #" }, | |
| 105 | + | { True, XK_comma, it_shell_cmd, (arg_t) "jpegtran -rotate 270 -copy all -outfile # #" }, | |
| 106 | + | { True, XK_period, it_shell_cmd, (arg_t) "jpegtran -rotate 90 -copy all -outfile # #" }, | |
| 103 | 107 | }; | |
| 104 | 108 | ||
| 105 | − | /* mouse button mappings for image mode: */ | |
| 109 | + | /* mouse button mappings for image mode: */ | |
| 106 | 110 | static const button_t buttons[] = { | |
| 107 | − | /* ctrl shift button function argument */ | |
| 108 | − | { False, False, Button1, navigate, (arg_t) +1 }, | |
| 109 | − | { False, False, Button3, navigate, (arg_t) -1 }, | |
| 110 | − | { False, False, Button2, drag, (arg_t) None }, | |
| 111 | − | { False, False, Button4, move, (arg_t) DIR_UP }, | |
| 112 | − | { False, False, Button5, move, (arg_t) DIR_DOWN }, | |
| 113 | − | { False, True, Button4, move, (arg_t) DIR_LEFT }, | |
| 114 | − | { False, True, Button5, move, (arg_t) DIR_RIGHT }, | |
| 115 | − | { True, False, Button4, zoom, (arg_t) +1 }, | |
| 116 | − | { True, False, Button5, zoom, (arg_t) -1 }, | |
| 111 | + | /* ctrl shift button function argument */ | |
| 112 | + | { False, False, Button1, i_navigate, (arg_t) +1 }, | |
| 113 | + | { False, False, Button3, i_navigate, (arg_t) -1 }, | |
| 114 | + | { False, False, Button2, i_drag, (arg_t) None }, | |
| 115 | + | { False, False, Button4, it_move, (arg_t) DIR_UP }, | |
| 116 | + | { False, False, Button5, it_move, (arg_t) DIR_DOWN }, | |
| 117 | + | { False, True, Button4, it_move, (arg_t) DIR_LEFT }, | |
| 118 | + | { False, True, Button5, it_move, (arg_t) DIR_RIGHT }, | |
| 119 | + | { True, False, Button4, i_zoom, (arg_t) +1 }, | |
| 120 | + | { True, False, Button5, i_zoom, (arg_t) -1 }, | |
| 117 | 121 | }; | |
| 118 | 122 | ||
| 119 | 123 | #endif | |
| @@ -93,7 +93,7 @@ void on_keypress(XKeyEvent *kev) { | |||
| 93 | 93 | ||
| 94 | 94 | for (i = 0; i < LEN(keys); i++) { | |
| 95 | 95 | if (keys[i].ksym == ksym && keymask(&keys[i], kev->state)) { | |
| 96 | − | if (keys[i].handler && keys[i].handler(keys[i].arg)) | |
| 96 | + | if (keys[i].cmd && keys[i].cmd(keys[i].arg)) | |
| 97 | 97 | redraw(); | |
| 98 | 98 | return; | |
| 99 | 99 | } | |
| @@ -114,7 +114,7 @@ void on_buttonpress(XButtonEvent *bev) { | |||
| 114 | 114 | if (buttons[i].button == bev->button && | |
| 115 | 115 | buttonmask(&buttons[i], bev->state)) | |
| 116 | 116 | { | |
| 117 | − | if (buttons[i].handler && buttons[i].handler(buttons[i].arg)) | |
| 117 | + | if (buttons[i].cmd && buttons[i].cmd(buttons[i].arg)) | |
| 118 | 118 | redraw(); | |
| 119 | 119 | return; | |
| 120 | 120 | } | |
| @@ -241,23 +241,32 @@ void run() { | |||
| 241 | 241 | } | |
| 242 | 242 | ||
| 243 | 243 | ||
| 244 | − | /* handler functions for key and button mappings: */ | |
| 244 | + | /* command functions for key and button mappings: */ | |
| 245 | 245 | ||
| 246 | − | int quit(arg_t a) { | |
| 246 | + | int it_quit(arg_t a) { | |
| 247 | 247 | cleanup(); | |
| 248 | 248 | exit(0); | |
| 249 | 249 | } | |
| 250 | 250 | ||
| 251 | − | int reload(arg_t a) { | |
| 251 | + | int it_switch_mode(arg_t a) { | |
| 252 | 252 | if (mode == MODE_NORMAL) { | |
| 253 | − | load_image(fileidx); | |
| 254 | − | return 1; | |
| 253 | + | if (!tns.thumbs) | |
| 254 | + | tns_init(&tns, filecnt); | |
| 255 | + | img_close(&img, 0); | |
| 256 | + | win_set_cursor(&win, CURSOR_ARROW); | |
| 257 | + | timo_cursor = 0; | |
| 258 | + | tns.sel = fileidx; | |
| 259 | + | tns.dirty = 1; | |
| 260 | + | mode = MODE_THUMBS; | |
| 255 | 261 | } else { | |
| 256 | − | return 0; | |
| 262 | + | timo_cursor = TO_CURSOR_HIDE; | |
| 263 | + | load_image(tns.sel); | |
| 264 | + | mode = MODE_NORMAL; | |
| 257 | 265 | } | |
| 266 | + | return 1; | |
| 258 | 267 | } | |
| 259 | 268 | ||
| 260 | − | int toggle_fullscreen(arg_t a) { | |
| 269 | + | int it_toggle_fullscreen(arg_t a) { | |
| 261 | 270 | win_toggle_fullscreen(&win); | |
| 262 | 271 | if (mode == MODE_NORMAL) | |
| 263 | 272 | img.checkpan = 1; | |
| @@ -267,43 +276,35 @@ int toggle_fullscreen(arg_t a) { | |||
| 267 | 276 | return 0; | |
| 268 | 277 | } | |
| 269 | 278 | ||
| 270 | − | int toggle_antialias(arg_t a) { | |
| 279 | + | int it_reload_image(arg_t a) { | |
| 271 | 280 | if (mode == MODE_NORMAL) { | |
| 272 | − | img_toggle_antialias(&img); | |
| 273 | − | return 1; | |
| 274 | − | } else { | |
| 275 | − | return 0; | |
| 281 | + | load_image(fileidx); | |
| 282 | + | } else if (!tns_load(&tns, tns.sel, &files[tns.sel], 0)) { | |
| 283 | + | remove_file(tns.sel, 0); | |
| 284 | + | tns.dirty = 1; | |
| 285 | + | if (tns.sel >= tns.cnt) | |
| 286 | + | tns.sel = tns.cnt - 1; | |
| 276 | 287 | } | |
| 288 | + | return 1; | |
| 277 | 289 | } | |
| 278 | 290 | ||
| 279 | − | int toggle_alpha(arg_t a) { | |
| 291 | + | int it_remove_image(arg_t a) { | |
| 280 | 292 | if (mode == MODE_NORMAL) { | |
| 281 | − | img.alpha ^= 1; | |
| 293 | + | remove_file(fileidx, 1); | |
| 294 | + | load_image(fileidx >= filecnt ? filecnt - 1 : fileidx); | |
| 282 | 295 | return 1; | |
| 283 | − | } else { | |
| 284 | − | return 0; | |
| 285 | − | } | |
| 286 | − | } | |
| 287 | − | ||
| 288 | − | int switch_mode(arg_t a) { | |
| 289 | − | if (mode == MODE_NORMAL) { | |
| 290 | − | if (!tns.thumbs) | |
| 291 | − | tns_init(&tns, filecnt); | |
| 292 | − | img_close(&img, 0); | |
| 293 | − | win_set_cursor(&win, CURSOR_ARROW); | |
| 294 | − | timo_cursor = 0; | |
| 295 | − | tns.sel = fileidx; | |
| 296 | + | } else if (tns.sel < tns.cnt) { | |
| 297 | + | remove_file(tns.sel, 1); | |
| 296 | 298 | tns.dirty = 1; | |
| 297 | − | mode = MODE_THUMBS; | |
| 299 | + | if (tns.sel >= tns.cnt) | |
| 300 | + | tns.sel = tns.cnt - 1; | |
| 301 | + | return 1; | |
| 298 | 302 | } else { | |
| 299 | − | timo_cursor = TO_CURSOR_HIDE; | |
| 300 | − | load_image(tns.sel); | |
| 301 | − | mode = MODE_NORMAL; | |
| 303 | + | return 0; | |
| 302 | 304 | } | |
| 303 | − | return 1; | |
| 304 | 305 | } | |
| 305 | 306 | ||
| 306 | − | int navigate(arg_t a) { | |
| 307 | + | int i_navigate(arg_t a) { | |
| 307 | 308 | int n = (int) a; | |
| 308 | 309 | ||
| 309 | 310 | if (mode == MODE_NORMAL) { | |
| @@ -321,7 +322,7 @@ int navigate(arg_t a) { | |||
| 321 | 322 | return 0; | |
| 322 | 323 | } | |
| 323 | 324 | ||
| 324 | − | int first(arg_t a) { | |
| 325 | + | int it_first(arg_t a) { | |
| 325 | 326 | if (mode == MODE_NORMAL && fileidx != 0) { | |
| 326 | 327 | load_image(0); | |
| 327 | 328 | return 1; | |
| @@ -334,7 +335,7 @@ int first(arg_t a) { | |||
| 334 | 335 | } | |
| 335 | 336 | } | |
| 336 | 337 | ||
| 337 | − | int last(arg_t a) { | |
| 338 | + | int it_last(arg_t a) { | |
| 338 | 339 | if (mode == MODE_NORMAL && fileidx != filecnt - 1) { | |
| 339 | 340 | load_image(filecnt - 1); | |
| 340 | 341 | return 1; | |
| @@ -347,23 +348,7 @@ int last(arg_t a) { | |||
| 347 | 348 | } | |
| 348 | 349 | } | |
| 349 | 350 | ||
| 350 | − | int remove_image(arg_t a) { | |
| 351 | − | if (mode == MODE_NORMAL) { | |
| 352 | − | remove_file(fileidx, 1); | |
| 353 | − | load_image(fileidx >= filecnt ? filecnt - 1 : fileidx); | |
| 354 | − | return 1; | |
| 355 | − | } else if (tns.sel < tns.cnt) { | |
| 356 | − | remove_file(tns.sel, 1); | |
| 357 | − | tns.dirty = 1; | |
| 358 | − | if (tns.sel >= tns.cnt) | |
| 359 | − | tns.sel = tns.cnt - 1; | |
| 360 | − | return 1; | |
| 361 | − | } else { | |
| 362 | − | return 0; | |
| 363 | − | } | |
| 364 | − | } | |
| 365 | − | ||
| 366 | − | int move(arg_t a) { | |
| 351 | + | int it_move(arg_t a) { | |
| 367 | 352 | direction_t dir = (direction_t) a; | |
| 368 | 353 | ||
| 369 | 354 | if (mode == MODE_NORMAL) | |
| @@ -372,7 +357,7 @@ int move(arg_t a) { | |||
| 372 | 357 | return tns_move_selection(&tns, &win, dir); | |
| 373 | 358 | } | |
| 374 | 359 | ||
| 375 | − | int pan_screen(arg_t a) { | |
| 360 | + | int i_pan_screen(arg_t a) { | |
| 376 | 361 | direction_t dir = (direction_t) a; | |
| 377 | 362 | ||
| 378 | 363 | if (mode == MODE_NORMAL) | |
| @@ -381,7 +366,7 @@ int pan_screen(arg_t a) { | |||
| 381 | 366 | return 0; | |
| 382 | 367 | } | |
| 383 | 368 | ||
| 384 | − | int pan_edge(arg_t a) { | |
| 369 | + | int i_pan_edge(arg_t a) { | |
| 385 | 370 | direction_t dir = (direction_t) a; | |
| 386 | 371 | ||
| 387 | 372 | if (mode == MODE_NORMAL) | |
| @@ -390,12 +375,12 @@ int pan_edge(arg_t a) { | |||
| 390 | 375 | return 0; | |
| 391 | 376 | } | |
| 392 | 377 | ||
| 393 | − | /* Xlib helper function for drag() */ | |
| 378 | + | /* Xlib helper function for i_drag() */ | |
| 394 | 379 | Bool is_motionnotify(Display *d, XEvent *e, XPointer a) { | |
| 395 | 380 | return e != NULL && e->type == MotionNotify; | |
| 396 | 381 | } | |
| 397 | 382 | ||
| 398 | − | int drag(arg_t a) { | |
| 383 | + | int i_drag(arg_t a) { | |
| 399 | 384 | int dx = 0, dy = 0, i, ox, oy, x, y; | |
| 400 | 385 | unsigned int ui; | |
| 401 | 386 | Bool dragging = True, next = False; | |
| @@ -445,22 +430,7 @@ int drag(arg_t a) { | |||
| 445 | 430 | return 0; | |
| 446 | 431 | } | |
| 447 | 432 | ||
| 448 | − | int rotate(arg_t a) { | |
| 449 | − | direction_t dir = (direction_t) a; | |
| 450 | − | ||
| 451 | − | if (mode == MODE_NORMAL) { | |
| 452 | − | if (dir == DIR_LEFT) { | |
| 453 | − | img_rotate_left(&img, &win); | |
| 454 | − | return 1; | |
| 455 | − | } else if (dir == DIR_RIGHT) { | |
| 456 | − | img_rotate_right(&img, &win); | |
| 457 | − | return 1; | |
| 458 | − | } | |
| 459 | − | } | |
| 460 | − | return 0; | |
| 461 | − | } | |
| 462 | − | ||
| 463 | − | int zoom(arg_t a) { | |
| 433 | + | int i_zoom(arg_t a) { | |
| 464 | 434 | int scale = (int) a; | |
| 465 | 435 | ||
| 466 | 436 | if (mode != MODE_NORMAL) | |
| @@ -473,7 +443,7 @@ int zoom(arg_t a) { | |||
| 473 | 443 | return img_zoom(&img, &win, 1.0); | |
| 474 | 444 | } | |
| 475 | 445 | ||
| 476 | − | int fit_to_win(arg_t a) { | |
| 446 | + | int i_fit_to_win(arg_t a) { | |
| 477 | 447 | int ret; | |
| 478 | 448 | ||
| 479 | 449 | if (mode == MODE_NORMAL) { | |
| @@ -485,7 +455,7 @@ int fit_to_win(arg_t a) { | |||
| 485 | 455 | } | |
| 486 | 456 | } | |
| 487 | 457 | ||
| 488 | − | int fit_to_img(arg_t a) { | |
| 458 | + | int i_fit_to_img(arg_t a) { | |
| 489 | 459 | int ret, x, y; | |
| 490 | 460 | unsigned int w, h; | |
| 491 | 461 | ||
| @@ -504,7 +474,40 @@ int fit_to_img(arg_t a) { | |||
| 504 | 474 | } | |
| 505 | 475 | } | |
| 506 | 476 | ||
| 507 | − | int open_with(arg_t a) { | |
| 477 | + | int i_rotate(arg_t a) { | |
| 478 | + | direction_t dir = (direction_t) a; | |
| 479 | + | ||
| 480 | + | if (mode == MODE_NORMAL) { | |
| 481 | + | if (dir == DIR_LEFT) { | |
| 482 | + | img_rotate_left(&img, &win); | |
| 483 | + | return 1; | |
| 484 | + | } else if (dir == DIR_RIGHT) { | |
| 485 | + | img_rotate_right(&img, &win); | |
| 486 | + | return 1; | |
| 487 | + | } | |
| 488 | + | } | |
| 489 | + | return 0; | |
| 490 | + | } | |
| 491 | + | ||
| 492 | + | int i_toggle_antialias(arg_t a) { | |
| 493 | + | if (mode == MODE_NORMAL) { | |
| 494 | + | img_toggle_antialias(&img); | |
| 495 | + | return 1; | |
| 496 | + | } else { | |
| 497 | + | return 0; | |
| 498 | + | } | |
| 499 | + | } | |
| 500 | + | ||
| 501 | + | int i_toggle_alpha(arg_t a) { | |
| 502 | + | if (mode == MODE_NORMAL) { | |
| 503 | + | img.alpha ^= 1; | |
| 504 | + | return 1; | |
| 505 | + | } else { | |
| 506 | + | return 0; | |
| 507 | + | } | |
| 508 | + | } | |
| 509 | + | ||
| 510 | + | int it_open_with(arg_t a) { | |
| 508 | 511 | const char *prog = (const char*) a; | |
| 509 | 512 | pid_t pid; | |
| 510 | 513 | ||
| @@ -523,7 +526,7 @@ int open_with(arg_t a) { | |||
| 523 | 526 | return 0; | |
| 524 | 527 | } | |
| 525 | 528 | ||
| 526 | − | int run_command(arg_t a) { | |
| 529 | + | int it_shell_cmd(arg_t a) { | |
| 527 | 530 | const char *cline = (const char*) a; | |
| 528 | 531 | char *cn, *cmdline; | |
| 529 | 532 | const char *co, *fpath; | |
| @@ -22,11 +22,12 @@ | |||
| 22 | 22 | #include <X11/Xlib.h> | |
| 23 | 23 | ||
| 24 | 24 | typedef void* arg_t; | |
| 25 | + | typedef int (*command_f)(arg_t); | |
| 25 | 26 | ||
| 26 | 27 | typedef struct { | |
| 27 | 28 | Bool ctrl; | |
| 28 | 29 | KeySym ksym; | |
| 29 | − | int (*handler)(arg_t); | |
| 30 | + | command_f cmd; | |
| 30 | 31 | arg_t arg; | |
| 31 | 32 | } keymap_t; | |
| 32 | 33 | ||
| @@ -34,32 +35,32 @@ typedef struct { | |||
| 34 | 35 | Bool ctrl; | |
| 35 | 36 | Bool shift; | |
| 36 | 37 | unsigned int button; | |
| 37 | − | int (*handler)(arg_t); | |
| 38 | + | command_f cmd; | |
| 38 | 39 | arg_t arg; | |
| 39 | 40 | } button_t; | |
| 40 | 41 | ||
| 41 | 42 | void run(); | |
| 42 | 43 | ||
| 43 | − | /* handler functions for key and button mappings: */ | |
| 44 | − | int quit(arg_t); | |
| 45 | − | int reload(arg_t); | |
| 46 | − | int toggle_fullscreen(arg_t); | |
| 47 | − | int toggle_antialias(arg_t); | |
| 48 | − | int toggle_alpha(arg_t); | |
| 49 | − | int switch_mode(arg_t); | |
| 50 | − | int navigate(arg_t); | |
| 51 | − | int first(arg_t); | |
| 52 | − | int last(arg_t); | |
| 53 | − | int remove_image(arg_t); | |
| 54 | − | int move(arg_t); | |
| 55 | − | int pan_screen(arg_t); | |
| 56 | − | int pan_edge(arg_t); | |
| 57 | − | int drag(arg_t); | |
| 58 | − | int rotate(arg_t); | |
| 59 | − | int zoom(arg_t); | |
| 60 | − | int fit_to_win(arg_t); | |
| 61 | − | int fit_to_img(arg_t); | |
| 62 | − | int open_with(arg_t); | |
| 63 | − | int run_command(arg_t); | |
| 44 | + | /* command functions for key and button mappings: */ | |
| 45 | + | int it_quit(arg_t); | |
| 46 | + | int it_switch_mode(arg_t); | |
| 47 | + | int it_toggle_fullscreen(arg_t); | |
| 48 | + | int it_reload_image(arg_t); | |
| 49 | + | int it_remove_image(arg_t); | |
| 50 | + | int i_navigate(arg_t); | |
| 51 | + | int it_first(arg_t); | |
| 52 | + | int it_last(arg_t); | |
| 53 | + | int it_move(arg_t); | |
| 54 | + | int i_pan_screen(arg_t); | |
| 55 | + | int i_pan_edge(arg_t); | |
| 56 | + | int i_drag(arg_t); | |
| 57 | + | int i_zoom(arg_t); | |
| 58 | + | int i_fit_to_win(arg_t); | |
| 59 | + | int i_fit_to_img(arg_t); | |
| 60 | + | int i_rotate(arg_t); | |
| 61 | + | int i_toggle_antialias(arg_t); | |
| 62 | + | int i_toggle_alpha(arg_t); | |
| 63 | + | int it_open_with(arg_t); | |
| 64 | + | int it_shell_cmd(arg_t); | |
| 64 | 65 | ||
| 65 | 66 | #endif /* EVENTS_H */ | |