Commit b58c4618 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Use buttons config instead of button options

parent 9c5b74ae
Loading
Loading
Loading
Loading
+64 −60
Original line number Diff line number Diff line
@@ -517,66 +517,6 @@ mode.
.El
.
.
.Sh BUTTON OPTIONS
.
.Bl -tag -width indent
.
.It Cm -0 , --reload-button Ar int
.
Set button to reload the image
.Pq default: 0 .
.
.It Cm -1 , --pan-button Ar int
.
Set button to pan the image
.Pq hold button down and move mouse to move the image .
When the mouse is not moved, advances to the next image in slideshow mode.
.Pq default: 1 , usually the left button .
.
.It Cm -2 , --zoom-button Ar int
.
Set button to enable zoom mode
.Pq default: 2 , usually the middle button .
.
.It Cm -3 , --menu-button Ar int
.
Set button to activate the menu.
.Pq default: 3 , usually the right button .
.
.It Cm --menu-ctrl-mask
.
Require CTRL+Button for menu activation.
.
.It Cm -4 , --prev-button Ar int
.
Set button to switch to the previous image in slideshow mode
.Pq default: 4 , usually Aq mousewheel up .
.
.It Cm -5 , --next-button Ar int
.
Set button to switch to the next image in slideshow mode
.Pq default: 5 , usually Aq mousewheel down .
.
.It Cm -8 , --rotate-button Ar int
.
Use CTRL+Button to rotate the current image
.Pq default : 2 .
.
.It Cm --no-rotate-ctrl-mask
.
Don't require CTRL+Button for rotation - just use the button.
.
.It Cm -9 , --blur-button Ar int
.
Use CTRL+Button for blurring
.Pq default : 1 .
.
.It Cm --no-blur-ctrl-mask
.
Don't require CTRL+Button for blurring - just use the button.
.El
.
.
.Sh MONTAGE MODE OPTIONS
.
These additional options can be used for index, montage and
@@ -1167,6 +1107,70 @@ Select highlighted menu item
.El
.
.
.Sh BUTTONS CONFIG SYNTAX
.
This works like the keys config file: the entries are of the form
.Qq Ar action Op Ar binding .
.
.Pp
.
Each
.Ar binding
is a button name.  It may optionally start with modifiers for things like
Control, in which case
.Ar binding
looks like
.Ar mod Ns No - Ns Ar button
.Pq for example "C-1" for Ctrl + Left button .
.
.Pp
.
For the available modifiers, see
.Sx KEYS CONFIGURATION SYNTAX .
.
.
.Ss BUTTONS
.
In an image window, the following buttons may be used
.Pq The strings in Bo square brackets Bc are the config action names :
.
.Bl -tag -width indent
.
.It Bq reload
.
Reload current image
.
.It 1 Ao left mouse button Ac Bq pan
.
pan the current image
.
.It 2 Ao middle mouse button Ac Bq zoom
.
Zoom the current image
.
.It 3 Ao right mouse button Ac Bq menu
.
Toggle menu
.
.It 4 Ao mousewheel down Ac Bq prev
.
Show previous image
.
.It 5 Ao mousewheel up Ac Bq next
.
Show next image
.
.It Ctrl+1 Bq blur
.
Blur current image
.
.It Ctrl+2 Bq rotate
.
Rotate current image
.
.El
.
.
.Sh MOUSE ACTIONS
.
When viewing an image, by default mouse button 1 pans
+156 −21
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "events.h"
#include "thumbnail.h"

fehbb buttons;

feh_event_handler *ev_handler[LASTEvent];

static void feh_event_handle_ButtonPress(XEvent * ev);
@@ -41,6 +43,129 @@ 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(fehbutton *bb, int modifier, char button)
{
	bb->modifier = modifier;
	bb->button = button;
}

static void feh_set_parse_bb_partial(fehbutton *button, char *binding)
{
	char *cur = binding;
	int mod = 0;

	if (!*binding) {
		button->button = 0;
		return;
	}

	while (cur[1] == '-') {
		switch (cur[0]) {
			case 'C':
				mod |= ControlMask;
				break;
			case 'S':
				mod |= ShiftMask;
				break;
			case '1':
				mod |= Mod1Mask;
				break;
			case '4':
				mod |= Mod4Mask;
				break;
			default:
				weprintf("buttons: invalid modifier %c in \"%s\"", cur[0], binding);
				break;
		}
		cur += 2;
	}

	button->button = atoi(cur);
	button->modifier = mod;
}

void init_buttonbindings(void)
{
	char *home = NULL;
	char *confhome = NULL;
	char *confpath = NULL;
	char line[128];
	char action[32], button[8];
	struct __fehbutton *cur_bb = NULL;
	FILE *conf = NULL;
	int read = 0;

	memset(&buttons, 0, sizeof(buttons));

	feh_set_bb(&buttons.reload, 0, 0);
	feh_set_bb(&buttons.pan,    0, 1);
	feh_set_bb(&buttons.zoom,   0, 2);
	feh_set_bb(&buttons.menu,   0, 3);
	feh_set_bb(&buttons.prev,   0, 4);
	feh_set_bb(&buttons.next,   0, 5);
	feh_set_bb(&buttons.blur,   4, 1);
	feh_set_bb(&buttons.rotate, 4, 2);

	home = getenv("HOME");
	if (!home)
		eprintf("No HOME in environment");

	confhome = getenv("XDG_CONFIG_HOME");

	if (confhome)
		confpath = estrjoin("/", confhome, "feh/buttons", NULL);
	else
		confpath = estrjoin("/", home, ".config/feh/buttons", NULL);

	conf = fopen(confpath, "r");

	free(confpath);

	if (!conf && ((conf = fopen("/etc/feh/buttons", "r")) == NULL))
		return;

	while (fgets(line, sizeof(line), conf)) {
		*action = '\0';
		*button = '\0';

		read = sscanf(line, "%31s %7s\n", (char *) &action, (char *) &button);

		if ((read == EOF) || (read == 0) || (line[0] == '#'))
			continue;

		if (!strcmp(action, "reload"))
			cur_bb = &buttons.reload;
		else if (!strcmp(action, "pan"))
			cur_bb = &buttons.pan;
		else if (!strcmp(action, "zoom"))
			cur_bb = &buttons.zoom;
		else if (!strcmp(action, "menu"))
			cur_bb = &buttons.menu;
		else if (!strcmp(action, "prev"))
			cur_bb = &buttons.prev;
		else if (!strcmp(action, "next"))
			cur_bb = &buttons.next;
		else if (!strcmp(action, "blur"))
			cur_bb = &buttons.blur;
		else if (!strcmp(action, "rotate"))
			cur_bb = &buttons.rotate;
		else
			weprintf("buttons: Invalid action: %s", action);

		if (cur_bb)
			feh_set_parse_bb_partial(cur_bb, button);
	}
	fclose(conf);
}

static short feh_is_bb(fehbutton *bb, int button, int mod)
{
	if ((bb->modifier == mod) && (bb->button == button))
		return 1;
	return 0;
}


void feh_event_init(void)
{
	int i;
@@ -62,6 +187,7 @@ void feh_event_init(void)
static void feh_event_handle_ButtonPress(XEvent * ev)
{
	winwidget winwid = NULL;
	int state, button;

	/* get the heck out if it's a mouse-click on the
	   cover, we'll hide the menus on release */
@@ -74,31 +200,34 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
		return;
	}

	if (!opt.no_menus && EV_IS_MENU_BUTTON(ev)) {
	state = ev->xbutton.state & (ControlMask | ShiftMask | Mod1Mask | Mod4Mask);
	button = ev->xbutton.button;

	if (!opt.no_menus && feh_is_bb(&buttons.menu, button, state)) {
		D(("Menu Button Press event\n"));
		winwidget_show_menu(winwid);
	} else if ((ev->xbutton.button == opt.rotate_button)
		   && (winwid->type != WIN_TYPE_THUMBNAIL)
		   && ((opt.no_rotate_ctrl_mask)
		       || (ev->xbutton.state & ControlMask))) {

	} else if (feh_is_bb(&buttons.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 ((ev->xbutton.button == opt.blur_button)
		   && (winwid->type != WIN_TYPE_THUMBNAIL)
		   && ((opt.no_blur_ctrl_mask)
		       || (ev->xbutton.state & ControlMask))) {

	} else if (feh_is_bb(&buttons.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 (ev->xbutton.button == opt.pan_button) {

	} else if (feh_is_bb(&buttons.pan, button, state)) {
		D(("Next button, but could be pan mode\n"));
		opt.mode = MODE_NEXT;
		winwid->mode = MODE_NEXT;
		D(("click offset is %d,%d\n", ev->xbutton.x, ev->xbutton.y));
		winwid->click_offset_x = ev->xbutton.x - winwid->im_x;
		winwid->click_offset_y = ev->xbutton.y - winwid->im_y;
	} else if (ev->xbutton.button == opt.zoom_button) {

	} else if (feh_is_bb(&buttons.zoom, button, state)) {
		D(("Zoom Button Press event\n"));
		opt.mode = MODE_ZOOM;
		winwid->mode = MODE_ZOOM;
@@ -112,17 +241,21 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
				- winwid->im_x) / winwid->old_zoom;
		winwid->im_click_offset_y = (winwid->click_offset_y
				- winwid->im_y) / winwid->old_zoom;
	} else if (ev->xbutton.button == opt.reload_button) {

	} else if (feh_is_bb(&buttons.reload, button, state)) {
		D(("Reload Button Press event\n"));
			feh_reload_image(winwid, 0, 1);
	} else if (ev->xbutton.button == opt.prev_button) {

	} else if (feh_is_bb(&buttons.prev, button, state)) {
		D(("Prev Button Press event\n"));
		if (winwid->type == WIN_TYPE_SLIDESHOW)
			slideshow_change_image(winwid, SLIDE_PREV, 1);
	} else if (ev->xbutton.button == opt.next_button) {

	} else if (feh_is_bb(&buttons.next, button, state)) {
		D(("Next Button Press event\n"));
		if (winwid->type == WIN_TYPE_SLIDESHOW)
			slideshow_change_image(winwid, SLIDE_NEXT, 1);

	} else {
		D(("Received other ButtonPress event\n"));
	}
@@ -132,6 +265,8 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
static void feh_event_handle_ButtonRelease(XEvent * ev)
{
	winwidget winwid = NULL;
	int state = ev->xbutton.state & (ControlMask | ShiftMask | Mod1Mask | Mod4Mask);
	int button = ev->xbutton.button;

	if (menu_root) {
		/* if menus are open, close them, and execute action if needed */
@@ -156,7 +291,7 @@ static void feh_event_handle_ButtonRelease(XEvent * ev)
		return;
	}

	if (ev->xbutton.button == opt.pan_button) {
	if (feh_is_bb(&buttons.pan, button, state)) {
		if (opt.mode == MODE_PAN) {
			D(("Disabling pan mode\n"));
			opt.mode = MODE_NORMAL;
@@ -186,13 +321,14 @@ static void feh_event_handle_ButtonRelease(XEvent * ev)
			opt.mode = MODE_NORMAL;
			winwid->mode = MODE_NORMAL;
		}
	} else if ((ev->xbutton.button == opt.rotate_button)
			|| (ev->xbutton.button == opt.zoom_button)) {

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

		if ((ev->xbutton.button == opt.zoom_button)
		if ((feh_is_bb(&buttons.zoom, button, state))
				&& (ev->xbutton.x == winwid->click_offset_x)
				&& (ev->xbutton.y == winwid->click_offset_y)) {
			winwid->zoom = 1.0;
@@ -201,9 +337,8 @@ static void feh_event_handle_ButtonRelease(XEvent * ev)
			winwidget_sanitise_offsets(winwid);

		winwidget_render_image(winwid, 0, 0);
	} else if ((ev->xbutton.button == opt.blur_button)
			&& ((opt.no_blur_ctrl_mask)
				|| (ev->xbutton.state & ControlMask))) {

	} else if (feh_is_bb(&buttons.blur, button, state)) {
		D(("Disabling Blur mode\n"));
		opt.mode = MODE_NORMAL;
		winwid->mode = MODE_NORMAL;
+0 −2
Original line number Diff line number Diff line
@@ -32,6 +32,4 @@ extern feh_event_handler *ev_handler[];

void feh_event_init(void);

#define EV_IS_MENU_BUTTON(ev) ((((ev)->xbutton.button == opt.menu_button) || (opt.menu_button == 0)) && (((!opt.menu_ctrl_mask) && (!((ev)->xbutton.state & ControlMask))) || (((ev)->xbutton.state & ControlMask) && (opt.menu_ctrl_mask))))

#endif
+1 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ void slideshow_change_image(winwidget winwid, int change, int render);
void slideshow_pause_toggle(winwidget w);
char *slideshow_create_name(feh_file * file);
void init_keyevents(void);
void init_buttonbindings(void);
void feh_event_handle_keypress(XEvent * ev);
void feh_action_run(feh_file * file, char *action);
char *feh_printf(char *str, feh_file * file);
+0 −24
Original line number Diff line number Diff line
@@ -80,30 +80,6 @@ OPTIONS
 -B, --image-bg STYLE      Set background for transparent images and the like.
                           Accepted values: white, black, default
 -N, --no-menus            Don't load or show any menus.
 -0, --reload-button B     Use button B to reload the image (defaults to 0)
 -1, --pan-button B        Use button B pan the image (hold button down, move
                           the mouse to move the image around. Advances to the
                           next image when the mouse is not moved (defaults to
                           1, usually the left button).
 -2, --zoom-button B       Use button B to zoom the current image in any
                           mode (defaults to 2, usually the middle button).
 -3, --menu-button B       Click button B to activate the menu in any
                           mode.  Set to 0 for any button.  This option
                           is disabled if the -N or --no-menus option is set
                           (defaults to 3, usually the right button).
     --menu-ctrl-mask      Require CTRL+Button for menu activation
 -4, --prev-button B       Use button B to switch to the previous image
                           (defaults to 4, which usually is <mousewheel up>).
 -5, --next-button B       Use button B to switch to the next image
                           (defaults to 5, which usually is <mousewheel down>).
 -8, --rotate-button B     Use CTRL+Button B to rotate the current image in
                           any mode (default=2).
     --no-rotate-ctrl-mask Don't require CTRL+Button for rotation in
                           any mode -- just use the button (default=off).
 -9, --blur-button B       Use CTRL+Button B to blur the current image in
                           any mode (default=1).
     --no-blur-ctrl-mask   Don't require CTRL+Button for blurring in
                           any mode -- just use the button (default=off).
     --no-xinerama         Disable Xinerama support
     --no-screen-clip      Do not limit window size to screen size
 -Y, --hide-pointer        Hide the pointer
Loading