From e06ce8df076331c7a345627bab3e8a375f505fe1 Mon Sep 17 00:00:00 2001 From: jefromi Date: Wed, 4 Feb 2009 16:30:00 +0100 Subject: [PATCH] list_window: bell when searches wrap NCMPC triggers a bell whenever a search wraps. (Note that this means a double-bell whenever a wrapped search finds nothing.) I can see this being reasonable, if the playlist is short and the user is aware of which direction they want to search in. However if you predominantly use long playlists and don't know which direction your target is in, this means you get bells on half your searches. Since I could see people wanting it either way, my best idea is making the bell optional. Here's a patch to do that, defaulting to the current behavior. (I'm a little confused about defaults - looks like there are only default values for some in options.c - but it looks like this behaves as desired.) --- src/conf.c | 3 +++ src/list_window.c | 12 +++++++++--- src/list_window.h | 4 +++- src/options.c | 1 + src/options.h | 1 + src/screen_utils.c | 4 +++- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/conf.c b/src/conf.c index 67d048a..13dc5d5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -55,6 +55,7 @@ #define CONF_FIND_SHOW_LAST "find-show-last" #define CONF_AUDIBLE_BELL "audible-bell" #define CONF_VISIBLE_BELL "visible-bell" +#define CONF_BELL_ON_WRAP "bell-on-wrap" #define CONF_XTERM_TITLE "set-xterm-title" #define CONF_ENABLE_MOUSE "enable-mouse" #define CONF_CROSSFADE_TIME "crossfade-time" @@ -411,6 +412,8 @@ parse_line(char *line) options.audible_bell = str2bool(value); else if (!strcasecmp(CONF_VISIBLE_BELL, name)) options.visible_bell = str2bool(value); + else if (!strcasecmp(CONF_BELL_ON_WRAP, name)) + options.bell_on_wrap = str2bool(value); else if (!strcasecmp(CONF_XTERM_TITLE, name)) options.enable_xterm_title = str2bool(value); else if (!strcasecmp(CONF_ENABLE_MOUSE, name)) diff --git a/src/list_window.c b/src/list_window.c index 8ab35b1..f7da79e 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -216,7 +216,8 @@ list_window_find(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data, const char *str, - bool wrap) + bool wrap, + bool bell_on_wrap) { bool h; unsigned i = lw->selected + 1; @@ -236,7 +237,9 @@ list_window_find(struct list_window *lw, if (i == 0) /* empty list */ return 1; i=0; /* first item */ - screen_bell(); + if (bell_on_wrap) { + screen_bell(); + } } } while (wrap); @@ -249,6 +252,7 @@ list_window_rfind(struct list_window *lw, void *callback_data, const char *str, bool wrap, + bool bell_on_wrap, unsigned rows) { bool h; @@ -270,7 +274,9 @@ list_window_rfind(struct list_window *lw, } if (wrap) { i = rows - 1; /* last item */ - screen_bell(); + if (bell_on_wrap) { + screen_bell(); + } } } while (wrap); diff --git a/src/list_window.h b/src/list_window.h index 5506f8c..a103af2 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -97,7 +97,8 @@ list_window_find(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data, const char *str, - bool wrap); + bool wrap, + bool bell_on_wrap); /* find a string in a list window (reversed) */ bool @@ -106,6 +107,7 @@ list_window_rfind(struct list_window *lw, void *callback_data, const char *str, bool wrap, + bool bell_on_wrap, unsigned rows); #endif diff --git a/src/options.c b/src/options.c index 3f784d1..83ae5ff 100644 --- a/src/options.c +++ b/src/options.c @@ -58,6 +58,7 @@ options_t options = { .find_wrap = true, .wide_cursor = true, .audible_bell = true, + .bell_on_wrap = true, #ifndef NCMPC_MINI .scroll = DEFAULT_SCROLL, .welcome_screen_list = true, diff --git a/src/options.h b/src/options.h index c48d1b3..48a12f2 100644 --- a/src/options.h +++ b/src/options.h @@ -59,6 +59,7 @@ typedef struct { #endif bool audible_bell; bool visible_bell; + bool bell_on_wrap; #ifndef NCMPC_MINI bool enable_xterm_title; #endif diff --git a/src/screen_utils.c b/src/screen_utils.c index dd5afee..26f8811 100644 --- a/src/screen_utils.c +++ b/src/screen_utils.c @@ -194,11 +194,13 @@ screen_find(list_window_t *lw, callback_fn, callback_data, screen.findbuf, options.find_wrap, + options.bell_on_wrap, rows) : list_window_find(lw, callback_fn, callback_data, screen.findbuf, - options.find_wrap); + options.find_wrap, + options.bell_on_wrap); if (!found) { screen_status_printf(_("Unable to find \'%s\'"), screen.findbuf); -- 2.30.2