Code

list_window: bell when searches wrap
authorjefromi <jefromi@gmail.com>
Wed, 4 Feb 2009 15:30:00 +0000 (16:30 +0100)
committerMax Kellermann <max@duempel.org>
Mon, 9 Feb 2009 16:00:17 +0000 (17:00 +0100)
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
src/list_window.c
src/list_window.h
src/options.c
src/options.h
src/screen_utils.c

index 67d048ae6972eb43dec841e85ef56d5e2e588e2d..13dc5d50c5cdeb1c4ddd8891c49560cf902944f3 100644 (file)
@@ -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))
index 8ab35b10670d4d45e4d1c205500a234035cc99e8..f7da79ea147973f67db1b44acc86e791bd3076b3 100644 (file)
@@ -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);
 
index 5506f8c77e8eb7e68a5761db1fd94d5a34b59c75..a103af2608c8c8cce2d8b2eaadd43f94551a97b8 100644 (file)
@@ -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
index 3f784d11cc9c00ab23b84a1be23af8f7690790ba..83ae5ff6a63ab57456ef7568a8432f38b478a859 100644 (file)
@@ -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,
index c48d1b39044ff2495d9d239c66e7902913dd54b7..48a12f2b81e3eba8b89085f8670e858b51322abe 100644 (file)
@@ -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
index dd5afee0f17a4efc9350fb6420cf508e6b5e74b4..26f8811a7bb9fc901379a0d8a0f7f960160a7bc8 100644 (file)
@@ -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);