summaryrefslogtreecommitdiff
path: root/src/keyevents.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keyevents.c')
-rw-r--r--src/keyevents.c635
1 files changed, 415 insertions, 220 deletions
diff --git a/src/keyevents.c b/src/keyevents.c
index 7940973..e43ae33 100644
--- a/src/keyevents.c
+++ b/src/keyevents.c
@@ -1,6 +1,7 @@
/* keyevents.c
Copyright (C) 1999-2003 Tom Gilbert.
+Copyright (C) 2010-2011 Daniel Friesel.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
@@ -29,6 +30,276 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "winwidget.h"
#include "options.h"
+fehkb keys;
+
+static void feh_set_kb(fehkey *key, int s0, int y0, int s1, int y1, int s2, int y2) {
+ key->keystates[0] = s0;
+ key->keystates[1] = s1;
+ key->keystates[2] = s2;
+ key->keysyms[0] = y0;
+ key->keysyms[1] = y1;
+ key->keysyms[2] = y2;
+}
+
+static void feh_set_parse_kb_partial(fehkey *key, int index, char *ks) {
+ char *cur = ks;
+ int mod = 0;
+
+ if (!*ks) {
+ key->keysyms[index] = 0;
+ return;
+ }
+
+ if (ks[1] == '-') {
+ switch (ks[0]) {
+ case 'C':
+ mod = ControlMask;
+ break;
+ case '1':
+ mod = Mod1Mask;
+ break;
+ case '4':
+ mod = Mod4Mask;
+ break;
+ default:
+ weprintf("keys: invalid modifier %c in %s", ks[0], ks);
+ break;
+ }
+ cur = ks + 2;
+ }
+
+ key->keysyms[index] = XStringToKeysym(cur);
+ key->keystates[index] = mod;
+
+ if (key->keysyms[index] == NoSymbol)
+ weprintf("keys: Invalid keysym: %s", cur);
+}
+
+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.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, 0 , 0, 0);
+ feh_set_kb(&keys.zoom_fit , 0, XK_KP_Divide , 0, 0 , 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, 0 , 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);
+ 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.reload_minus, 0, XK_minus, 0, 0, 0, 0);
+ feh_set_kb(&keys.reload_plus, 0, XK_plus, 0, 0, 0, 0);
+
+ home = getenv("HOME");
+ if (!home)
+ eprintf("No HOME in environment\n");
+
+ confhome = getenv("XDG_CONFIG_HOME");
+
+ if (confhome)
+ confpath = estrjoin("/", confhome, "feh/keys", NULL);
+ else
+ confpath = estrjoin("/", home, ".config/feh/keys", NULL);
+
+ 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, "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;
+ 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, "reload_minus"))
+ cur_kb = &keys.reload_minus;
+ else if (!strcmp(action, "reload_plus"))
+ cur_kb = &keys.reload_plus;
+ 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);
+ }
+ }
+ fclose(conf);
+}
+
+static short feh_is_kp(fehkey *key, int sym, int state) {
+ int i;
+
+ for (i = 0; i < 3; i++) {
+ if (
+ (key->keysyms[i] == sym) &&
+ (key->keystates[i] == state))
+ return 1;
+ else if (key->keysyms[i] == 0)
+ return 0;
+ }
+ return 0;
+}
+
void feh_event_invoke_action(winwidget winwid, unsigned char action)
{
if (opt.actions[action]) {
@@ -54,6 +325,7 @@ void feh_event_invoke_action(winwidget winwid, unsigned char action)
void feh_event_handle_keypress(XEvent * ev)
{
int len;
+ int state;
char kbuf[20];
KeySym keysym;
XKeyEvent *kev;
@@ -71,34 +343,23 @@ void feh_event_handle_keypress(XEvent * ev)
kev = (XKeyEvent *) ev;
len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(kbuf), &keysym, NULL);
+ state = kev->state & (ControlMask | Mod1Mask | Mod4Mask);
/* menus are showing, so this is a menu control keypress */
if (ev->xbutton.window == menu_cover) {
selected_item = feh_menu_find_selected_r(menu_root, &selected_menu);
- switch (keysym) {
- case XK_Escape:
+ if (feh_is_kp(&keys.menu_close, keysym, state))
feh_menu_hide(menu_root, True);
- break;
- case XK_Left:
+ else if (feh_is_kp(&keys.menu_parent, keysym, state))
feh_menu_select_parent(selected_menu);
- break;
- case XK_Down:
+ else if (feh_is_kp(&keys.menu_down, keysym, state))
feh_menu_select_next(selected_menu, selected_item);
- break;
- case XK_Up:
+ else if (feh_is_kp(&keys.menu_up, keysym, state))
feh_menu_select_prev(selected_menu, selected_item);
- break;
- case XK_Right:
+ else if (feh_is_kp(&keys.menu_child, keysym, state))
feh_menu_select_submenu(selected_menu);
- break;
- case XK_Return:
- case XK_space:
+ else if (feh_is_kp(&keys.menu_select, keysym, state))
feh_menu_item_activate(selected_menu, selected_item);
- break;
- default:
- break;
- }
-
return;
}
@@ -108,7 +369,7 @@ void feh_event_handle_keypress(XEvent * ev)
if (winwid->caption_entry) {
switch (keysym) {
case XK_Return:
- if (kev->state & ControlMask) {
+ if (state & ControlMask) {
/* insert actual newline */
ESTRAPPEND(FEH_FILE(winwid->file->data)->caption, "\n");
winwidget_render_image_cached(winwid);
@@ -116,14 +377,15 @@ void feh_event_handle_keypress(XEvent * ev)
/* finish caption entry, write to captions file */
FILE *fp;
char *caption_filename;
- caption_filename = build_caption_filename(FEH_FILE(winwid->file->data));
+ caption_filename =
+ build_caption_filename(FEH_FILE(winwid->file->data), 1);
winwid->caption_entry = 0;
winwidget_render_image_cached(winwid);
XFreePixmap(disp, winwid->bg_pmap_cache);
winwid->bg_pmap_cache = 0;
fp = fopen(caption_filename, "w");
if (!fp) {
- weprintf("couldn't write to captions file %s:", caption_filename);
+ eprintf("couldn't write to captions file %s:", caption_filename);
return;
}
fprintf(fp, "%s", FEH_FILE(winwid->file->data)->caption);
@@ -156,244 +418,179 @@ void feh_event_handle_keypress(XEvent * ev)
return;
}
- switch (keysym) {
- case XK_Left:
- if (kev->state & ControlMask) {
- winwid->im_x += 10;
- winwidget_render_image(winwid, 0, 0);
- }
- else if (opt.slideshow)
- slideshow_change_image(winwid, SLIDE_PREV);
- break;
- case XK_Right:
- if (kev->state & ControlMask) {
- winwid->im_x -= 10;
- winwidget_render_image(winwid, 0, 0);
- }
- else if (opt.slideshow)
+ if (feh_is_kp(&keys.next_img, keysym, state)) {
+ if (opt.slideshow)
slideshow_change_image(winwid, SLIDE_NEXT);
- break;
- case XK_Page_Up:
- case XK_KP_Page_Up:
+ }
+ else if (feh_is_kp(&keys.prev_img, keysym, state)) {
+ if (opt.slideshow)
+ slideshow_change_image(winwid, SLIDE_PREV);
+ }
+ else if (feh_is_kp(&keys.scroll_right, keysym, state)) {
+ winwid->im_x -= 20;
+ winwidget_render_image(winwid, 0, 1);
+ }
+ else if (feh_is_kp(&keys.scroll_left, keysym, state)) {
+ winwid->im_x += 20;
+ winwidget_render_image(winwid, 0, 1);
+ }
+ else if (feh_is_kp(&keys.scroll_down, keysym, state)) {
+ winwid->im_y -= 20;
+ winwidget_render_image(winwid, 0, 1);
+ }
+ else if (feh_is_kp(&keys.scroll_up, keysym, state)) {
+ winwid->im_y += 20;
+ winwidget_render_image(winwid, 0, 1);
+ }
+ else if (feh_is_kp(&keys.jump_back, keysym, state)) {
if (opt.slideshow)
slideshow_change_image(winwid, SLIDE_JUMP_BACK);
- break;
- case XK_Escape:
- winwidget_destroy_all();
- break;
- case XK_Page_Down:
- case XK_KP_Page_Down:
+ }
+ else if (feh_is_kp(&keys.jump_fwd, keysym, state)) {
if (opt.slideshow)
slideshow_change_image(winwid, SLIDE_JUMP_FWD);
- break;
- case XK_Delete:
- /* Holding ctrl gets you a filesystem deletion and removal from the *
- filelist. Just DEL gets you filelist removal only. */
- if (kev->state & ControlMask) {
- if (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)
- feh_thumbnail_mark_removed(FEH_FILE(winwid->file->data), 1);
- feh_filelist_image_remove(winwid, 1);
- } else {
- if (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)
- feh_thumbnail_mark_removed(FEH_FILE(winwid->file->data), 0);
- feh_filelist_image_remove(winwid, 0);
- }
- break;
- case XK_Home:
- case XK_KP_Home:
+ }
+ else if (feh_is_kp(&keys.quit, keysym, state)) {
+ winwidget_destroy_all();
+ }
+ else if (feh_is_kp(&keys.delete, keysym, state)) {
+ if (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)
+ feh_thumbnail_mark_removed(FEH_FILE(winwid->file->data), 1);
+ feh_filelist_image_remove(winwid, 1);
+ }
+ else if (feh_is_kp(&keys.remove, keysym, state)) {
+ if (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)
+ feh_thumbnail_mark_removed(FEH_FILE(winwid->file->data), 0);
+ feh_filelist_image_remove(winwid, 0);
+ }
+ else if (feh_is_kp(&keys.jump_first, keysym, state)) {
if (opt.slideshow)
slideshow_change_image(winwid, SLIDE_FIRST);
- break;
- case XK_End:
- case XK_KP_End:
+ }
+ else if (feh_is_kp(&keys.jump_last, keysym, state)) {
if (opt.slideshow)
slideshow_change_image(winwid, SLIDE_LAST);
- break;
- case XK_Return:
- case XK_KP_Enter:
- case XK_0:
- case XK_KP_0:
+ }
+ else if (feh_is_kp(&keys.action_0, keysym, state)) {
feh_event_invoke_action(winwid, 0);
- break;
- case XK_1:
- case XK_KP_1:
+ }
+ else if (feh_is_kp(&keys.action_1, keysym, state)) {
feh_event_invoke_action(winwid, 1);
- break;
- case XK_2:
- case XK_KP_2:
+ }
+ else if (feh_is_kp(&keys.action_2, keysym, state)) {
feh_event_invoke_action(winwid, 2);
- break;
- case XK_3:
- case XK_KP_3:
+ }
+ else if (feh_is_kp(&keys.action_3, keysym, state)) {
feh_event_invoke_action(winwid, 3);
- break;
- case XK_4:
- case XK_KP_4:
+ }
+ else if (feh_is_kp(&keys.action_4, keysym, state)) {
feh_event_invoke_action(winwid, 4);
- break;
- case XK_5:
- case XK_KP_5:
+ }
+ else if (feh_is_kp(&keys.action_5, keysym, state)) {
feh_event_invoke_action(winwid, 5);
- break;
- case XK_6:
- case XK_KP_6:
+ }
+ else if (feh_is_kp(&keys.action_6, keysym, state)) {
feh_event_invoke_action(winwid, 6);
- break;
- case XK_7:
- case XK_KP_7:
+ }
+ else if (feh_is_kp(&keys.action_7, keysym, state)) {
feh_event_invoke_action(winwid, 7);
- break;
- case XK_8:
- case XK_KP_8:
+ }
+ else if (feh_is_kp(&keys.action_8, keysym, state)) {
feh_event_invoke_action(winwid, 8);
- break;
- case XK_9:
- case XK_KP_9:
+ }
+ else if (feh_is_kp(&keys.action_9, keysym, state)) {
feh_event_invoke_action(winwid, 9);
- break;
- case XK_KP_Left:
- winwid->im_x += 10;
- winwidget_render_image(winwid, 0, 0);
- break;
- case XK_KP_Right:
- winwid->im_x -= 10;
- winwidget_render_image(winwid, 0, 0);
- break;
- case XK_KP_Up:
- winwid->im_y += 10;
+ }
+ else if (feh_is_kp(&keys.zoom_in, keysym, state)) {
+ winwid->old_zoom = winwid->zoom;
+ winwid->zoom = winwid->zoom * 1.25;
+ winwid->im_x = (winwid->w / 2) - (((winwid->w / 2) - winwid->im_x) /
+ winwid->old_zoom * winwid->zoom);
+ winwid->im_y = (winwid->h / 2) - (((winwid->h / 2) - winwid->im_y) /
+ winwid->old_zoom * winwid->zoom);
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
- break;
- case XK_KP_Down:
- winwid->im_y -= 10;
+ }
+ else if (feh_is_kp(&keys.zoom_out, keysym, state)) {
+ winwid->old_zoom = winwid->zoom;
+ winwid->zoom = winwid->zoom * 0.80;
+ winwid->im_x = (winwid->w / 2) - (((winwid->w / 2) - winwid->im_x) /
+ winwid->old_zoom * winwid->zoom);
+ winwid->im_y = (winwid->h / 2) - (((winwid->h / 2) - winwid->im_y) /
+ winwid->old_zoom * winwid->zoom);
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
- break;
- case XK_KP_Add:
- case XK_Up:
- if (kev->state & ControlMask) {
- winwid->im_y += 10;
- winwidget_render_image(winwid, 0, 0);
- }
- else {
- /* erroneously recognized as '+' in the *kbuf switch. Work around this. */
- len = 0;
- winwid->old_zoom = winwid->zoom;
- winwid->zoom = winwid->zoom * 1.25;
- winwid->im_x = (winwid->w / 2) - (((winwid->w / 2) - winwid->im_x) /
- winwid->old_zoom * winwid->zoom);
- winwid->im_y = (winwid->h / 2) - (((winwid->h / 2) - winwid->im_y) /
- winwid->old_zoom * winwid->zoom);
- winwidget_sanitise_offsets(winwid);
- winwidget_render_image(winwid, 0, 1);
- }
- break;
- case XK_KP_Subtract:
- case XK_Down:
- if (kev->state & ControlMask) {
- winwid->im_y -= 10;
- winwidget_render_image(winwid, 0, 0);
- }
- else {
- len = 0;
- winwid->old_zoom = winwid->zoom;
- winwid->zoom = winwid->zoom * 0.75;
- winwid->im_x = (winwid->w / 2) - (((winwid->w / 2) - winwid->im_x) /
- winwid->old_zoom * winwid->zoom);
- winwid->im_y = (winwid->h / 2) - (((winwid->h / 2) - winwid->im_y) /
- winwid->old_zoom * winwid->zoom);
- winwidget_sanitise_offsets(winwid);
- winwidget_render_image(winwid, 0, 1);
- }
- break;
- case XK_KP_Multiply:
- len = 0;
+ }
+ else if (feh_is_kp(&keys.zoom_default, keysym, state)) {
winwid->zoom = 1;
+ winwid->old_zoom = 1.001; /* hack for --scale-down */
winwidget_center_image(winwid);
winwidget_render_image(winwid, 0, 0);
- break;
- case XK_KP_Divide:
- len = 0;
+ }
+ else if (feh_is_kp(&keys.zoom_fit, keysym, state)) {
feh_calc_needed_zoom(&winwid->zoom, winwid->im_w, winwid->im_h, winwid->w, winwid->h);
winwidget_center_image(winwid);
- winwidget_render_image(winwid, 0, 1);
- break;
- case XK_KP_Begin:
- winwidget_render_image(winwid, 0, 1);
- break;
- default:
- break;
+ winwidget_render_image(winwid, 0, 0);
}
-
- if (len <= 0 || len > (int) sizeof(kbuf))
- return;
- kbuf[len] = '\0';
-
- switch (*kbuf) {
- case 'a':
+ else if (feh_is_kp(&keys.render, keysym, state)) {
+ winwidget_render_image(winwid, 0, 0);
+ }
+ else if (feh_is_kp(&keys.toggle_actions, keysym, state)) {
opt.draw_actions = !opt.draw_actions;
- winwidget_rerender_all(0, 1);
- break;
- case 'd':
+ winwidget_rerender_all(0);
+ }
+ else if (feh_is_kp(&keys.toggle_aliasing, keysym, state)) {
+ opt.force_aliasing = !opt.force_aliasing;
+ winwidget_rerender_all(0);
+ }
+ else if (feh_is_kp(&keys.toggle_filenames, keysym, state)) {
opt.draw_filename = !opt.draw_filename;
- winwidget_rerender_all(0, 1);
- break;
- case 'n':
- case ' ':
- if (opt.slideshow)
- slideshow_change_image(winwid, SLIDE_NEXT);
- break;
- case 'o':
+ winwidget_rerender_all(0);
+ }
+ else if (feh_is_kp(&keys.toggle_pointer, keysym, state)) {
winwidget_set_pointer(winwid, opt.hide_pointer);
opt.hide_pointer = !opt.hide_pointer;
- break;
- case 'p':
- case '\b':
- if (opt.slideshow)
- slideshow_change_image(winwid, SLIDE_PREV);
- break;
- case 'z':
- if (opt.slideshow)
- slideshow_change_image(winwid, SLIDE_RAND);
- break;
- case 'q':
- winwidget_destroy_all();
- break;
- case 'c':
+ }
+ else if (feh_is_kp(&keys.jump_random, keysym, state)) {
+ slideshow_change_image(winwid, SLIDE_RAND);
+ }
+ else if (feh_is_kp(&keys.toggle_caption, keysym, state)) {
if (opt.caption_path)
winwid->caption_entry = 1;
- winwidget_render_image(winwid, 0, 1);
- break;
- case 'r':
+ winwidget_render_image(winwid, 0, 0);
+ }
+ else if (feh_is_kp(&keys.reload_image, keysym, state)) {
feh_reload_image(winwid, 0, 0);
- break;
- case 'h':
+ }
+ else if (feh_is_kp(&keys.toggle_pause, keysym, state)) {
slideshow_pause_toggle(winwid);
- break;
- case 's':
+ }
+ else if (feh_is_kp(&keys.save_image, keysym, state)) {
slideshow_save_image(winwid);
- break;
- case 'f':
+ }
+ else if (feh_is_kp(&keys.save_filelist, keysym, state)) {
if ((winwid->type == WIN_TYPE_THUMBNAIL)
|| (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER))
weprintf("Filelist saving is not supported in thumbnail mode");
else
feh_save_filelist();
- break;
- case 'w':
+ }
+ else if (feh_is_kp(&keys.size_to_image, keysym, state)) {
winwidget_size_to_image(winwid);
- break;
- case 'm':
+ }
+ else if (feh_is_kp(&keys.toggle_menu, keysym, state)) {
winwidget_show_menu(winwid);
- break;
- case 'x':
+ }
+ else if (feh_is_kp(&keys.close, keysym, state)) {
winwidget_destroy(winwid);
- break;
- case '>':
+ }
+ else if (feh_is_kp(&keys.orient_1, keysym, state)) {
feh_edit_inplace_orient(winwid, 1);
- break;
- case '<':
+ }
+ else if (feh_is_kp(&keys.orient_3, keysym, state)) {
feh_edit_inplace_orient(winwid, 3);
- break;
- case 'v':
+ }
+ else if (feh_is_kp(&keys.toggle_fullscreen, keysym, state)) {
#ifdef HAVE_LIBXINERAMA
if (opt.xinerama && xinerama_screens) {
int i, rect[4];
@@ -425,7 +622,7 @@ void feh_event_handle_keypress(XEvent * ev)
winwid->full_screen = !winwid->full_screen;
winwidget_destroy_xwin(winwid);
winwidget_create_window(winwid, winwid->im_w, winwid->im_h);
- winwidget_render_image(winwid, 1, 1);
+ winwidget_render_image(winwid, 1, 0);
winwidget_show(winwid);
#ifdef HAVE_LIBXINERAMA
/* if we have xinerama and we're using it, then full screen the window
@@ -436,20 +633,18 @@ void feh_event_handle_keypress(XEvent * ev)
xinerama_screens[curr_screen].x_org, xinerama_screens[curr_screen].y_org);
}
#endif /* HAVE_LIBXINERAMA */
- case '+':
+ }
+ else if (feh_is_kp(&keys.reload_plus, keysym, state)){
if (opt.reload < SLIDESHOW_RELOAD_MAX)
opt.reload++;
else if (opt.verbose)
weprintf("Cannot set RELOAD higher than %d seconds.", opt.reload);
- break;
- case '-':
+ }
+ else if (feh_is_kp(&keys.reload_minus, keysym, state)) {
if (opt.reload > 1)
opt.reload--;
else if (opt.verbose)
weprintf("Cannot set RELOAD lower than 1 second.");
- break;
- default:
- break;
}
return;
}