Commit 1ed8c690 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Replace keybinding struct with an array of named bindings

parent 7eb9d73e
Loading
Loading
Loading
Loading
+40 −56
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define FEH_JITTER_OFFSET 2
#define FEH_JITTER_TIME 1

extern fehkb keys;
extern struct __fehkey keys[EVENT_LIST_END];
fehkey *feh_str_to_kb(char *action);

feh_event_handler *ev_handler[LASTEvent];

@@ -45,10 +46,10 @@ static void feh_event_handle_LeaveNotify(XEvent * ev);
static void feh_event_handle_MotionNotify(XEvent * ev);
static void feh_event_handle_ClientMessage(XEvent * ev);

static void feh_set_bb(fehkey *bb, int modifier, char button)
static void feh_set_bb(unsigned int bb_index, int modifier, char button)
{
	bb->state  = modifier;
	bb->button = button;
	keys[bb_index].state  = modifier;
	keys[bb_index].button = button;
}

static void feh_set_parse_bb_partial(fehkey *button, char *binding)
@@ -101,13 +102,13 @@ void init_buttonbindings(void)
	FILE *conf = NULL;
	int read = 0;

	feh_set_bb(&keys.pan,         0, 1);
	feh_set_bb(&keys.zoom,        0, 2);
	feh_set_bb(&keys.toggle_menu, 0, 3);
	feh_set_bb(&keys.prev_img,    0, 4);
	feh_set_bb(&keys.next_img,    0, 5);
	feh_set_bb(&keys.blur,        4, 1);
	feh_set_bb(&keys.rotate,      4, 2);
	feh_set_bb(EVENT_pan,         0, 1);
	feh_set_bb(EVENT_zoom,        0, 2);
	feh_set_bb(EVENT_toggle_menu, 0, 3);
	feh_set_bb(EVENT_prev_img,    0, 4);
	feh_set_bb(EVENT_next_img,    0, 5);
	feh_set_bb(EVENT_blur,        4, 1);
	feh_set_bb(EVENT_rotate,      4, 2);

	home = getenv("HOME");
	confhome = getenv("XDG_CONFIG_HOME");
@@ -136,34 +137,17 @@ void init_buttonbindings(void)
		if ((read == EOF) || (read == 0) || (line[0] == '#'))
			continue;

		/*
		 * Note: This isn't really good code. But it works, and since it only
		 * runs once for each button config line the runtime penalty compared to
		 * e.g. a hash table is negligible in this case.
		 */
		if (!strcmp(action, "reload"))
			cur_bb = &keys.reload;
		else if (!strcmp(action, "pan"))
			cur_bb = &keys.pan;
		else if (!strcmp(action, "zoom"))
			cur_bb = &keys.zoom;
		else if (!strcmp(action, "menu") || !strcmp(action, "toggle_menu"))
			cur_bb = &keys.toggle_menu;
		else if (!strcmp(action, "prev") || !strcmp(action, "prev_img"))
			cur_bb = &keys.prev_img;
		else if (!strcmp(action, "next") || !strcmp(action, "next_img"))
			cur_bb = &keys.next_img;
		else if (!strcmp(action, "blur"))
			cur_bb = &keys.blur;
		else if (!strcmp(action, "rotate"))
			cur_bb = &keys.rotate;
		else if (!strcmp(action, "zoom_in"))
			cur_bb = &keys.zoom_in;
		else if (!strcmp(action, "zoom_out"))
			cur_bb = &keys.zoom_out;
		else
		cur_bb = feh_str_to_kb(action);

		if (cur_bb == NULL) {
			if (!strcmp(action, "reload"))
				cur_bb = &keys[EVENT_reload_image];
			else if (!strcmp(action, "menu"))
				cur_bb = &keys[EVENT_toggle_menu];
			else if (!strcmp(action, "prev"))
				cur_bb = &keys[EVENT_prev_img];
			else if (!strcmp(action, "next"))
				cur_bb = &keys[EVENT_next_img];
		}
		if (cur_bb)
			feh_set_parse_bb_partial(cur_bb, button);
		else
@@ -172,9 +156,9 @@ void init_buttonbindings(void)
	fclose(conf);
}

static short feh_is_bb(fehkey *bb, unsigned int button, unsigned int mod)
static short feh_is_bb(unsigned int key_index, unsigned int button, unsigned int mod)
{
	if ((bb->state == mod) && (bb->button == button))
	if ((keys[key_index].state == mod) && (keys[key_index].button == button))
		return 1;
	return 0;
}
@@ -217,23 +201,23 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
	state = ev->xbutton.state & (ControlMask | ShiftMask | Mod1Mask | Mod4Mask);
	button = ev->xbutton.button;

	if (!opt.no_menus && feh_is_bb(&keys.toggle_menu, button, state)) {
	if (!opt.no_menus && feh_is_bb(EVENT_toggle_menu, button, state)) {
		D(("Menu Button Press event\n"));
		winwidget_show_menu(winwid);

	} else if (feh_is_bb(&keys.rotate, button, state)
	} else if (feh_is_bb(EVENT_rotate, button, state)
		   && (winwid->type != WIN_TYPE_THUMBNAIL)) {
		opt.mode = MODE_ROTATE;
		winwid->mode = MODE_ROTATE;
		D(("rotate starting at %d, %d\n", ev->xbutton.x, ev->xbutton.y));

	} else if (feh_is_bb(&keys.blur, button, state)
	} else if (feh_is_bb(EVENT_blur, button, state)
		   && (winwid->type != WIN_TYPE_THUMBNAIL)) {
		opt.mode = MODE_BLUR;
		winwid->mode = MODE_BLUR;
		D(("blur starting at %d, %d\n", ev->xbutton.x, ev->xbutton.y));

	} else if (feh_is_bb(&keys.pan, button, state)) {
	} else if (feh_is_bb(EVENT_pan, button, state)) {
		D(("Next button, but could be pan mode\n"));
		opt.mode = MODE_NEXT;
		winwid->mode = MODE_NEXT;
@@ -242,7 +226,7 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
		winwid->click_offset_y = ev->xbutton.y - winwid->im_y;
		winwid->click_start_time = time(NULL);

	} else if (feh_is_bb(&keys.zoom, button, state)) {
	} else if (feh_is_bb(EVENT_zoom, button, state)) {
		D(("Zoom Button Press event\n"));
		opt.mode = MODE_ZOOM;
		winwid->mode = MODE_ZOOM;
@@ -257,7 +241,7 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
		winwid->im_click_offset_y = (winwid->click_offset_y
				- winwid->im_y) / winwid->old_zoom;

	} else if (feh_is_bb(&keys.zoom_in, button, state)) {
	} else if (feh_is_bb(EVENT_zoom_in, button, state)) {
		D(("Zoom_In Button Press event\n"));
		D(("click offset is %d,%d\n", ev->xbutton.x, ev->xbutton.y));
		winwid->click_offset_x = ev->xbutton.x;
@@ -285,7 +269,7 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
		winwidget_sanitise_offsets(winwid);
		winwidget_render_image(winwid, 0, 0);

	} else if (feh_is_bb(&keys.zoom_out, button, state)) {
	} else if (feh_is_bb(EVENT_zoom_out, button, state)) {
		D(("Zoom_Out Button Press event\n"));
		D(("click offset is %d,%d\n", ev->xbutton.x, ev->xbutton.y));
		winwid->click_offset_x = ev->xbutton.x;
@@ -313,16 +297,16 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
		winwidget_sanitise_offsets(winwid);
		winwidget_render_image(winwid, 0, 0);

	} else if (feh_is_bb(&keys.reload, button, state)) {
	} else if (feh_is_bb(EVENT_reload_image, button, state)) {
		D(("Reload Button Press event\n"));
			feh_reload_image(winwid, 0, 1);

	} else if (feh_is_bb(&keys.prev_img, button, state)) {
	} else if (feh_is_bb(EVENT_prev_img, button, state)) {
		D(("Prev Button Press event\n"));
		if (winwid->type == WIN_TYPE_SLIDESHOW)
			slideshow_change_image(winwid, SLIDE_PREV, 1);

	} else if (feh_is_bb(&keys.next_img, button, state)) {
	} else if (feh_is_bb(EVENT_next_img, button, state)) {
		D(("Next Button Press event\n"));
		if (winwid->type == WIN_TYPE_SLIDESHOW)
			slideshow_change_image(winwid, SLIDE_NEXT, 1);
@@ -363,7 +347,7 @@ static void feh_event_handle_ButtonRelease(XEvent * ev)
		return;
	}

	if (feh_is_bb(&keys.pan, button, state)) {
	if (feh_is_bb(EVENT_pan, button, state)) {
		if (opt.mode == MODE_PAN) {
			D(("Disabling pan mode\n"));
			opt.mode = MODE_NORMAL;
@@ -401,13 +385,13 @@ static void feh_event_handle_ButtonRelease(XEvent * ev)
			winwid->mode = MODE_NORMAL;
		}

	} else if (feh_is_bb(&keys.rotate, button, state)
			|| feh_is_bb(&keys.zoom, button, state)) {
	} else if (feh_is_bb(EVENT_rotate, button, state)
			|| feh_is_bb(EVENT_zoom, button, state)) {
		D(("Disabling mode\n"));
		opt.mode = MODE_NORMAL;
		winwid->mode = MODE_NORMAL;

		if ((feh_is_bb(&keys.zoom, button, state))
		if ((feh_is_bb(EVENT_zoom, button, state))
				&& (ev->xbutton.x == winwid->click_offset_x)
				&& (ev->xbutton.y == winwid->click_offset_y)) {
			winwid->zoom = 1.0;
@@ -417,7 +401,7 @@ static void feh_event_handle_ButtonRelease(XEvent * ev)

		winwidget_render_image(winwid, 0, 0);

	} else if (feh_is_bb(&keys.blur, button, state)) {
	} else if (feh_is_bb(EVENT_blur, button, state)) {
		D(("Disabling Blur mode\n"));
		opt.mode = MODE_NORMAL;
		winwid->mode = MODE_NORMAL;
+160 −273

File changed.

Preview size limit exceeded, changes collapsed.

+72 −71
Original line number Diff line number Diff line
@@ -134,81 +134,82 @@ struct __fehkey {
	unsigned int keystates[3];
	unsigned int state;
	unsigned int button;
	char *name;
};

struct __fehkb {
	struct __fehkey menu_close;
	struct __fehkey menu_parent;
	struct __fehkey menu_down;
	struct __fehkey menu_up;
	struct __fehkey menu_child;
	struct __fehkey menu_select;
	struct __fehkey scroll_right;
	struct __fehkey prev_img;
	struct __fehkey scroll_left;
	struct __fehkey next_img;
	struct __fehkey scroll_up;
	struct __fehkey scroll_down;
	struct __fehkey scroll_right_page;
	struct __fehkey scroll_left_page;
	struct __fehkey scroll_up_page;
	struct __fehkey scroll_down_page;
	struct __fehkey jump_back;
	struct __fehkey quit;
	struct __fehkey jump_fwd;
	struct __fehkey prev_dir;
	struct __fehkey next_dir;
	struct __fehkey remove;
	struct __fehkey delete;
	struct __fehkey jump_first;
	struct __fehkey jump_last;
	struct __fehkey action_0;
	struct __fehkey action_1;
	struct __fehkey action_2;
	struct __fehkey action_3;
	struct __fehkey action_4;
	struct __fehkey action_5;
	struct __fehkey action_6;
	struct __fehkey action_7;
	struct __fehkey action_8;
	struct __fehkey action_9;
	struct __fehkey zoom_in;
	struct __fehkey zoom_out;
	struct __fehkey zoom_default;
	struct __fehkey zoom_fit;
	struct __fehkey zoom_fill;
	struct __fehkey render;
	struct __fehkey toggle_actions;
	struct __fehkey toggle_filenames;
enum key_action {
	EVENT_menu_close = 0,
	EVENT_menu_parent,
	EVENT_menu_down,
	EVENT_menu_up,
	EVENT_menu_child,
	EVENT_menu_select,
	EVENT_scroll_left,
	EVENT_scroll_right,
	EVENT_scroll_down,
	EVENT_scroll_up,
	EVENT_scroll_left_page,
	EVENT_scroll_right_page,
	EVENT_scroll_down_page,
	EVENT_scroll_up_page,
	EVENT_prev_img,
	EVENT_next_img,
	EVENT_jump_back,
	EVENT_jump_fwd,
	EVENT_prev_dir,
	EVENT_next_dir,
	EVENT_jump_random,
	EVENT_quit,
	EVENT_close,
	EVENT_remove,
	EVENT_delete,
	EVENT_jump_first,
	EVENT_jump_last,
	EVENT_action_0,
	EVENT_action_1,
	EVENT_action_2,
	EVENT_action_3,
	EVENT_action_4,
	EVENT_action_5,
	EVENT_action_6,
	EVENT_action_7,
	EVENT_action_8,
	EVENT_action_9,
	EVENT_zoom_in,
	EVENT_zoom_out,
	EVENT_zoom_default,
	EVENT_zoom_fit,
	EVENT_zoom_fill,
	EVENT_size_to_image,
	EVENT_render,
	EVENT_toggle_actions,
	EVENT_toggle_aliasing,
#ifdef HAVE_LIBEXIF
	struct __fehkey toggle_exif;
	EVENT_toggle_exif,
#endif
	struct __fehkey toggle_info;
	struct __fehkey toggle_pointer;
	struct __fehkey toggle_aliasing;
	struct __fehkey jump_random;
	struct __fehkey toggle_caption;
	struct __fehkey toggle_pause;
	struct __fehkey reload_image;
	struct __fehkey save_image;
	struct __fehkey save_filelist;
	struct __fehkey size_to_image;
	struct __fehkey toggle_menu;
	struct __fehkey close;
	struct __fehkey orient_1;
	struct __fehkey orient_3;
	struct __fehkey flip;
	struct __fehkey mirror;
	struct __fehkey toggle_fullscreen;
	struct __fehkey reload_minus;
	struct __fehkey reload_plus;
	struct __fehkey toggle_keep_vp;
	struct __fehkey pan;
	struct __fehkey zoom;
	struct __fehkey reload;
	struct __fehkey blur;
	struct __fehkey rotate;
	struct __fehkey toggle_fixed_geometry;
	EVENT_toggle_filenames,
	EVENT_toggle_info,
	EVENT_toggle_pointer,
	EVENT_toggle_caption,
	EVENT_toggle_pause,
	EVENT_toggle_menu,
	EVENT_toggle_fullscreen,
	EVENT_reload_image,
	EVENT_save_image,
	EVENT_save_filelist,
	EVENT_orient_1,
	EVENT_orient_3,
	EVENT_flip,
	EVENT_mirror,
	EVENT_reload_minus,
	EVENT_reload_plus,
	EVENT_toggle_keep_vp,
	EVENT_toggle_fixed_geometry,
	EVENT_pan,
	EVENT_zoom,
	EVENT_blur,
	EVENT_rotate,
	EVENT_LIST_END
};

void init_parse_options(int argc, char **argv);