]> git.sesse.net Git - vlc/blobdiff - modules/gui/ncurses.c
macosx: fixed minor display issue with the Equalizer button (#4654)
[vlc] / modules / gui / ncurses.c
index 07c42398f5a6ea335142e6d4c9b6c0a128400576..b920f5b5c65328c3b720e0aa8d8b73051cadcce7 100644 (file)
@@ -51,6 +51,7 @@
 #include <vlc_playlist.h>
 #include <vlc_meta.h>
 #include <vlc_fs.h>
+#include <vlc_url.h>
 
 #include <assert.h>
 
@@ -181,6 +182,7 @@ struct intf_sys_t
     input_thread_t *p_input;
 
     bool            b_color;
+    bool            b_exit;
 
     int             i_box_type;
     int             i_box_y;            // start of box content
@@ -209,7 +211,6 @@ struct intf_sys_t
     bool            b_show_hidden_files;
 
     /* Playlist context */
-    bool            category_view;
     struct pl_item_t    **pp_plist;
     int             i_plist_entries;
     bool            b_need_update;
@@ -258,7 +259,7 @@ static bool IsFile(const char *current_dir, const char *entry)
     char *uri;
     struct stat st;
 
-    if (asprintf(&uri, "%s/%s", current_dir, entry) != -1)
+    if (asprintf(&uri, "%s" DIR_SEP "%s", current_dir, entry) != -1)
     {
         ret = vlc_stat(uri, &st) || !S_ISDIR(st.st_mode);
         free(uri);
@@ -328,9 +329,10 @@ next:
  *****************************************************************************/
 static void CheckIdx(intf_sys_t *p_sys)
 {
+    int lines = p_sys->i_box_lines_total;
     int height = LINES - p_sys->i_box_y - 2;
-    if (height > p_sys->i_box_lines_total - 1)
-        height = p_sys->i_box_lines_total - 1;
+    if (height > lines - 1)
+        height = lines - 1;
 
     /* make sure the new index is within the box */
     if (p_sys->i_box_idx <= 0)
@@ -338,9 +340,9 @@ static void CheckIdx(intf_sys_t *p_sys)
         p_sys->i_box_idx = 0;
         p_sys->i_box_start = 0;
     }
-    else if (p_sys->i_box_idx >= p_sys->i_box_lines_total - 1)
+    else if (p_sys->i_box_idx >= lines - 1 && lines > 0)
     {
-        p_sys->i_box_idx = p_sys->i_box_lines_total - 1;
+        p_sys->i_box_idx = lines - 1;
         p_sys->i_box_start = p_sys->i_box_idx - height;
     }
 
@@ -373,14 +375,6 @@ static void PlaylistDestroy(intf_sys_t *p_sys)
     p_sys->pp_plist = NULL;
 }
 
-static inline playlist_item_t *PlaylistGetRoot(intf_thread_t *p_intf)
-{
-    playlist_t *p_playlist = pl_Get(p_intf);
-    return p_intf->p_sys->category_view ?
-        p_playlist->p_root_category :
-        p_playlist->p_root_onelevel;
-}
-
 static bool PlaylistAddChild(intf_sys_t *p_sys, playlist_item_t *p_child,
                              const char *c, const char d)
 {
@@ -449,7 +443,7 @@ static void PlaylistRebuild(intf_thread_t *p_intf)
 
     PL_LOCK;
     PlaylistDestroy(p_sys);
-    PlaylistAddNode(p_sys, PlaylistGetRoot(p_intf), "");
+    PlaylistAddNode(p_sys, p_playlist->p_root_onelevel, "");
     PL_UNLOCK;
 }
 
@@ -470,16 +464,6 @@ static int PlaylistChanged(vlc_object_t *p_this, const char *psz_variable,
 }
 
 /* Playlist suxx */
-/* This function have to be called with the playlist locked */
-static inline bool PlaylistIsPlaying(playlist_t *p_playlist,
-                                     playlist_item_t *p_item)
-{
-    playlist_item_t *p_played_item = playlist_CurrentPlayingItem(p_playlist);
-    return p_item                && p_played_item
-        && p_item->p_input       && p_played_item->p_input
-        && p_item->p_input->i_id == p_played_item->p_input->i_id;
-}
-
 static int SubSearchPlaylist(intf_sys_t *p_sys, char *psz_searchstring,
                               int i_start, int i_stop)
 {
@@ -518,8 +502,18 @@ static void SearchPlaylist(intf_sys_t *p_sys, char *psz_searchstring)
 static inline bool IsIndex(intf_sys_t *p_sys, playlist_t *p_playlist, int i)
 {
     playlist_item_t *p_item = p_sys->pp_plist[i]->p_item;
-    return (p_item->i_children == 0 && p_item == p_sys->p_node) ||
-            PlaylistIsPlaying(p_playlist, p_item);
+    playlist_item_t *p_played_item;
+
+    PL_ASSERT_LOCKED;
+
+    if (p_item->i_children == 0 && p_item == p_sys->p_node)
+        return true;
+
+    p_played_item = playlist_CurrentPlayingItem(p_playlist);
+    if (p_played_item && p_item->p_input && p_played_item->p_input)
+        return p_item->p_input->i_id == p_played_item->p_input->i_id;
+
+    return false;
 }
 
 static void FindIndex(intf_sys_t *p_sys, playlist_t *p_playlist)
@@ -909,71 +903,75 @@ static int DrawHelp(intf_thread_t *p_intf)
     intf_sys_t *p_sys = p_intf->p_sys;
     int l = 0;
 
-    if (p_sys->b_color) color_set(C_CATEGORY, NULL);
-    MainBoxWrite(p_sys, l++, _("[Display]"));
-    if (p_sys->b_color) color_set(C_DEFAULT, NULL);
-    MainBoxWrite(p_sys, l++, _("     h,H         Show/Hide help box"));
-    MainBoxWrite(p_sys, l++, _("     i           Show/Hide info box"));
-    MainBoxWrite(p_sys, l++, _("     m           Show/Hide metadata box"));
-    MainBoxWrite(p_sys, l++, _("     L           Show/Hide messages box"));
-    MainBoxWrite(p_sys, l++, _("     P           Show/Hide playlist box"));
-    MainBoxWrite(p_sys, l++, _("     B           Show/Hide filebrowser"));
-    MainBoxWrite(p_sys, l++, _("     x           Show/Hide objects box"));
-    MainBoxWrite(p_sys, l++, _("     S           Show/Hide statistics box"));
-    MainBoxWrite(p_sys, l++, _("     Esc         Close Add/Search entry"));
-    MainBoxWrite(p_sys, l++, _("     Ctrl-l      Refresh the screen"));
-    MainBoxWrite(p_sys, l++, "");
+#define H(a) MainBoxWrite(p_sys, l++, a)
 
     if (p_sys->b_color) color_set(C_CATEGORY, NULL);
-    MainBoxWrite(p_sys, l++, _("[Global]"));
+    H(_("[Display]"));
     if (p_sys->b_color) color_set(C_DEFAULT, NULL);
-    MainBoxWrite(p_sys, l++, _("     q, Q, Esc   Quit"));
-    MainBoxWrite(p_sys, l++, _("     s           Stop"));
-    MainBoxWrite(p_sys, l++, _("     <space>     Pause/Play"));
-    MainBoxWrite(p_sys, l++, _("     f           Toggle Fullscreen"));
-    MainBoxWrite(p_sys, l++, _("     n, p        Next/Previous playlist item"));
-    MainBoxWrite(p_sys, l++, _("     [, ]        Next/Previous title"));
-    MainBoxWrite(p_sys, l++, _("     <, >        Next/Previous chapter"));
-    MainBoxWrite(p_sys, l++, _("     ←, →        Seek -/+ 1%%"));
-    MainBoxWrite(p_sys, l++, _("     a, z        Volume Up/Down"));
-    MainBoxWrite(p_sys, l++, "");
+    H(_(" h,H                    Show/Hide help box"));
+    H(_(" i                      Show/Hide info box"));
+    H(_(" m                      Show/Hide metadata box"));
+    H(_(" L                      Show/Hide messages box"));
+    H(_(" P                      Show/Hide playlist box"));
+    H(_(" B                      Show/Hide filebrowser"));
+    H(_(" x                      Show/Hide objects box"));
+    H(_(" S                      Show/Hide statistics box"));
+    H(_(" Esc                    Close Add/Search entry"));
+    H(_(" Ctrl-l                 Refresh the screen"));
+    H("");
 
     if (p_sys->b_color) color_set(C_CATEGORY, NULL);
-    MainBoxWrite(p_sys, l++, _("[Playlist]"));
+    H(_("[Global]"));
     if (p_sys->b_color) color_set(C_DEFAULT, NULL);
-    MainBoxWrite(p_sys, l++, _("     r           Toggle Random playing"));
-    MainBoxWrite(p_sys, l++, _("     l           Toggle Loop Playlist"));
-    MainBoxWrite(p_sys, l++, _("     R           Toggle Repeat item"));
-    MainBoxWrite(p_sys, l++, _("     o           Order Playlist by title"));
-    MainBoxWrite(p_sys, l++, _("     O           Reverse order Playlist by title"));
-    MainBoxWrite(p_sys, l++, _("     g           Go to the current playing item"));
-    MainBoxWrite(p_sys, l++, _("     /           Look for an item"));
-    MainBoxWrite(p_sys, l++, _("     A           Add an entry"));
-    MainBoxWrite(p_sys, l++, _("     D, ⌫, <del> Delete an entry"));
-    MainBoxWrite(p_sys, l++, _("     e           Eject (if stopped)"));
-    MainBoxWrite(p_sys, l++, "");
+    H(_(" q, Q, Esc              Quit"));
+    H(_(" s                      Stop"));
+    H(_(" <space>                Pause/Play"));
+    H(_(" f                      Toggle Fullscreen"));
+    H(_(" n, p                   Next/Previous playlist item"));
+    H(_(" [, ]                   Next/Previous title"));
+    H(_(" <, >                   Next/Previous chapter"));
+    /* xgettext: You can use ← and → characters */
+    H(_(" <left>,<right>         Seek -/+ 1%%"));
+    H(_(" a, z                   Volume Up/Down"));
+    /* xgettext: You can use ↑ and ↓ characters */
+    H(_(" <up>,<down>            Navigate through the box line by line"));
+    /* xgettext: You can use ⇞ and ⇟ characters */
+    H(_(" <pageup>,<pagedown>    Navigate through the box page by page"));
+    /* xgettext: You can use ↖ and ↘ characters */
+    H(_(" <start>,<end>          Navigate to start/end of box"));
+    H("");
 
     if (p_sys->b_color) color_set(C_CATEGORY, NULL);
-    MainBoxWrite(p_sys, l++, _("[Filebrowser]"));
+    H(_("[Playlist]"));
     if (p_sys->b_color) color_set(C_DEFAULT, NULL);
-    MainBoxWrite(p_sys, l++, _("     <enter>     Add the selected file to the playlist"));
-    MainBoxWrite(p_sys, l++, _("     <space>     Add the selected directory to the playlist"));
-    MainBoxWrite(p_sys, l++, _("     .           Show/Hide hidden files"));
-    MainBoxWrite(p_sys, l++, "");
+    H(_(" r                      Toggle Random playing"));
+    H(_(" l                      Toggle Loop Playlist"));
+    H(_(" R                      Toggle Repeat item"));
+    H(_(" o                      Order Playlist by title"));
+    H(_(" O                      Reverse order Playlist by title"));
+    H(_(" g                      Go to the current playing item"));
+    H(_(" /                      Look for an item"));
+    H(_(" A                      Add an entry"));
+    /* xgettext: You can use ⌫ character to translate <backspace> */
+    H(_(" D, <backspace>, <del>  Delete an entry"));
+    H(_(" e                      Eject (if stopped)"));
+    H("");
 
     if (p_sys->b_color) color_set(C_CATEGORY, NULL);
-    MainBoxWrite(p_sys, l++, _("[Boxes]"));
+    H(_("[Filebrowser]"));
     if (p_sys->b_color) color_set(C_DEFAULT, NULL);
-    MainBoxWrite(p_sys, l++, _("     ↑,↓         Navigate through the box line by line"));
-    MainBoxWrite(p_sys, l++, _("     ⇞,⇟         Navigate through the box page by page"));
-    MainBoxWrite(p_sys, l++, _("     ↖,↘         Navigate to start/end of box"));
-    MainBoxWrite(p_sys, l++, "");
+    H(_(" <enter>                Add the selected file to the playlist"));
+    H(_(" <space>                Add the selected directory to the playlist"));
+    H(_(" .                      Show/Hide hidden files"));
+    H("");
 
     if (p_sys->b_color) color_set(C_CATEGORY, NULL);
-    MainBoxWrite(p_sys, l++, _("[Player]"));
+    H(_("[Player]"));
     if (p_sys->b_color) color_set(C_DEFAULT, NULL);
-    MainBoxWrite(p_sys, l++, _("     ↑,↓         Seek +/-5%%"));
+    /* xgettext: You can use ↑ and ↓ characters */
+    H(_(" <up>,<down>            Seek +/-5%%"));
 
+#undef H
     return l;
 }
 
@@ -1010,29 +1008,23 @@ static int DrawPlaylist(intf_thread_t *p_intf)
 
     for(int i = 0; i < p_sys->i_plist_entries; i++)
     {
-        char c = ' ';
-        playlist_item_t *p_current_item, *p_item, *p_node;
-        input_thread_t *p_input2;
-
-        p_item = p_sys->pp_plist[i]->p_item;
-        p_node = p_sys->p_node;
-        p_input2 = playlist_CurrentInput(p_playlist);
+        char c;
+        playlist_item_t *p_current_item;
+        playlist_item_t *p_item = p_sys->pp_plist[i]->p_item;
+        playlist_item_t *p_node = p_sys->p_node;
 
         PL_LOCK;
         assert(p_item);
         p_current_item = playlist_CurrentPlayingItem(p_playlist);
         if ((p_node && p_item->p_input == p_node->p_input) ||
-                    (!p_node && p_input2 && p_current_item &&
-                      p_item->p_input == p_current_item->p_input))
+           (!p_node && p_current_item && p_item->p_input == p_current_item->p_input))
             c = '*';
-        else if (p_item == p_node || (p_item != p_node &&
-                    PlaylistIsPlaying(p_playlist, p_item)))
+        else if (p_item == p_node || p_current_item == p_item)
             c = '>';
+        else
+            c = ' ';
         PL_UNLOCK;
 
-        if (p_input2)
-            vlc_object_release(p_input2);
-
         if (p_sys->b_color) color_set(i%3 + C_PLAYLIST_1, NULL);
         MainBoxWrite(p_sys, i, "%c%s", c, p_sys->pp_plist[i]->psz_display);
         if (p_sys->b_color) color_set(C_DEFAULT, NULL);
@@ -1065,7 +1057,10 @@ static int DrawMessages(intf_thread_t *p_intf)
         if (i == p_sys->i_msgs) /* did we loop around the ring buffer ? */
             break;
     }
+
     vlc_mutex_unlock(&p_sys->msg_lock);
+    if (p_sys->b_color)
+        color_set(C_DEFAULT, NULL);
     return l;
 }
 
@@ -1137,7 +1132,7 @@ static int DrawStatus(intf_thread_t *p_intf)
 
             mvnprintw(y++, 0, COLS, _(" Position : %s/%s"), buf1, buf2);
 
-            aout_VolumeGet(p_playlist, &i_volume);
+            i_volume = aout_VolumeGet(p_playlist);
             mvnprintw(y++, 0, COLS, _(" Volume   : %i%%"),
                        i_volume*200/AOUT_VOLUME_MAX);
 
@@ -1211,7 +1206,7 @@ static void FillBox(intf_thread_t *p_intf)
         FillTextBox(p_sys);
 }
 
-static void Redraw(intf_thread_t *p_intf, time_t *t_last_refresh)
+static void Redraw(intf_thread_t *p_intf)
 {
     intf_sys_t *p_sys   = p_intf->p_sys;
     int         box     = p_sys->i_box_type;
@@ -1236,7 +1231,6 @@ static void Redraw(intf_thread_t *p_intf, time_t *t_last_refresh)
         DrawEmptyLine(y++, 1, COLS - 2);
 
     refresh();
-    *t_last_refresh = time(0);
 }
 
 static void ChangePosition(intf_thread_t *p_intf, float increment)
@@ -1362,18 +1356,12 @@ static bool HandlePlaylistKey(intf_thread_t *p_intf, int key)
     /* Playlist sort */
     case 'o':
     case 'O':
-        playlist_RecursiveNodeSort(p_playlist, PlaylistGetRoot(p_intf),
+        playlist_RecursiveNodeSort(p_playlist, p_playlist->p_root_onelevel,
                                     SORT_TITLE_NODES_FIRST,
                                     (key == 'o')? ORDER_NORMAL : ORDER_REVERSE);
         p_sys->b_need_update = true;
         return true;
 
-    /* Playlist view */
-    case 'v':
-        p_sys->category_view = !p_sys->category_view;
-        p_sys->b_need_update = true;
-        return true;
-
     case 'g':
         FindIndex(p_sys, p_playlist);
         return true;
@@ -1452,31 +1440,27 @@ static bool HandleBrowseKey(intf_thread_t *p_intf, int key)
     case '\n':
     case ' ':
         dir_entry = p_sys->pp_dir_entries[p_sys->i_box_idx];
+        char *psz_path;
+        if (asprintf(&psz_path, "%s" DIR_SEP "%s", p_sys->psz_current_dir,
+                     dir_entry->psz_path) == -1)
+            return true;
 
         if (!dir_entry->b_file && key != ' ')
         {
-            char *current_dir = p_sys->psz_current_dir;
-            if (asprintf(&p_sys->psz_current_dir, "%s/%s",
-                          p_sys->psz_current_dir, dir_entry->psz_path) != -1)
-            {
-                ReadDir(p_intf);
-                free(current_dir);
-            }
-            else
-                p_sys->psz_current_dir = current_dir;
+            free(p_sys->psz_current_dir);
+            p_sys->psz_current_dir = psz_path;
+            ReadDir(p_intf);
 
             p_sys->i_box_start = 0;
             p_sys->i_box_idx = 0;
             return true;
         }
 
-        char* psz_uri;
-        if (asprintf(&psz_uri, "%s://%s/%s",
-                    dir_entry->b_file ? "file" : "directory",
-                    p_sys->psz_current_dir, dir_entry->psz_path) == -1)
-        {
-            return false;
-        }
+        char *psz_uri = make_URI(psz_path, dir_entry->b_file ? "file"
+                                                             : "directory");
+        free(psz_path);
+        if (psz_uri == NULL)
+            return true;
 
         playlist_t *p_playlist = pl_Get(p_intf);
         playlist_item_t *p_parent = p_sys->p_node;
@@ -1498,7 +1482,7 @@ static bool HandleBrowseKey(intf_thread_t *p_intf, int key)
         playlist_Add(p_playlist, psz_uri, NULL, PLAYLIST_APPEND,
                       PLAYLIST_END, p_parent->p_input == p_input, false);
 
-        p_sys->i_box_type = BOX_PLAYLIST;
+        BoxSwitch(p_sys, BOX_PLAYLIST);
         free(psz_uri);
         return true;
     }
@@ -1506,7 +1490,7 @@ static bool HandleBrowseKey(intf_thread_t *p_intf, int key)
     return false;
 }
 
-static bool HandleEditBoxKey(intf_thread_t *p_intf, int key, int box)
+static void HandleEditBoxKey(intf_thread_t *p_intf, int key, int box)
 {
     intf_sys_t *p_sys = p_intf->p_sys;
     bool search = box == BOX_SEARCH;
@@ -1518,7 +1502,7 @@ static bool HandleEditBoxKey(intf_thread_t *p_intf, int key, int box)
     switch(key)
     {
     case 0x0c:  /* ^l */
-    case KEY_CLEAR:     clear(); return 1;
+    case KEY_CLEAR:     clear(); return;
 
     case KEY_ENTER:
     case '\r':
@@ -1532,6 +1516,13 @@ static bool HandleEditBoxKey(intf_thread_t *p_intf, int key, int box)
         }
         else if (len)
         {
+            char *psz_uri = make_URI(p_sys->psz_open_chain, NULL);
+            if (psz_uri == NULL)
+            {
+                p_sys->i_box_type = BOX_PLAYLIST;
+                return;
+            }
+
             playlist_t *p_playlist = pl_Get(p_intf);
             playlist_item_t *p_parent = p_sys->p_node, *p_current;
 
@@ -1548,21 +1539,22 @@ static bool HandleEditBoxKey(intf_thread_t *p_intf, int key, int box)
                 p_parent = p_parent->p_parent;
             PL_UNLOCK;
 
-            playlist_Add(p_playlist, p_sys->psz_open_chain, NULL,
+            playlist_Add(p_playlist, psz_uri, NULL,
                   PLAYLIST_APPEND|PLAYLIST_GO, PLAYLIST_END,
                   p_parent->p_input == p_playlist->p_local_onelevel->p_input,
                   false);
 
+            free(psz_uri);
             p_sys->b_plidx_follow = true;
         }
         p_sys->i_box_type = BOX_PLAYLIST;
-        return 1;
+        return;
 
     case 0x1b: /* ESC */
         /* Alt+key combinations return 2 keys in the terminal keyboard:
          * ESC, and the 2nd key.
          * If some other key is available immediately (where immediately
-         * means after wgetch() 1 second delay), that means that the
+         * means after getch() 1 second delay), that means that the
          * ESC key was not pressed.
          *
          * man 3X curs_getch says:
@@ -1574,11 +1566,11 @@ static bool HandleEditBoxKey(intf_thread_t *p_intf, int key, int box)
          *
          */
         if (getch() != ERR)
-            return 0;
+            return;
 
         if (search) p_sys->i_box_idx = p_sys->i_before_search;
         p_sys->i_box_type = BOX_PLAYLIST;
-        return 1;
+        return;
 
     case KEY_BACKSPACE:
     case 0x7f:
@@ -1586,8 +1578,8 @@ static bool HandleEditBoxKey(intf_thread_t *p_intf, int key, int box)
         break;
 
     default:
-        if (len + 1 < search ? sizeof p_sys->psz_search_chain
-                             : sizeof p_sys->psz_open_chain)
+        if (len + 1 < (search ? sizeof p_sys->psz_search_chain
+                              : sizeof p_sys->psz_open_chain))
         {
             str[len + 0] = (char) key;
             str[len + 1] = '\0';
@@ -1600,7 +1592,6 @@ static bool HandleEditBoxKey(intf_thread_t *p_intf, int key, int box)
         p_sys->psz_old_search = NULL;
         SearchPlaylist(p_sys, str);
     }
-    return 1;
 }
 
 static void InputNavigate(input_thread_t* p_input, const char *var)
@@ -1609,7 +1600,7 @@ static void InputNavigate(input_thread_t* p_input, const char *var)
         var_TriggerCallback(p_input, var);
 }
 
-static bool HandleCommonKey(intf_thread_t *p_intf, int key)
+static void HandleCommonKey(intf_thread_t *p_intf, int key)
 {
     intf_sys_t *p_sys = p_intf->p_sys;
     playlist_t *p_playlist = pl_Get(p_intf);
@@ -1617,39 +1608,51 @@ static bool HandleCommonKey(intf_thread_t *p_intf, int key)
     {
     case 0x1b:  /* ESC */
         if (getch() != ERR)
-            return false;
+            return;
 
     case 'q':
     case 'Q':
     case KEY_EXIT:
         libvlc_Quit(p_intf->p_libvlc);
-        return false;
+        p_sys->b_exit = true;           // terminate the main loop
+        return;
 
     case 'h':
-    case 'H': BoxSwitch(p_sys, BOX_HELP);       return true;
-    case 'i': BoxSwitch(p_sys, BOX_INFO);       return true;
-    case 'm': BoxSwitch(p_sys, BOX_META);       return true;
-    case 'L': BoxSwitch(p_sys, BOX_LOG);        return true;
-    case 'P': BoxSwitch(p_sys, BOX_PLAYLIST);   return true;
-    case 'B': BoxSwitch(p_sys, BOX_BROWSE);     return true;
-    case 'x': BoxSwitch(p_sys, BOX_OBJECTS);    return true;
-    case 'S': BoxSwitch(p_sys, BOX_STATS);      return true;
+    case 'H': BoxSwitch(p_sys, BOX_HELP);       return;
+    case 'i': BoxSwitch(p_sys, BOX_INFO);       return;
+    case 'm': BoxSwitch(p_sys, BOX_META);       return;
+    case 'L': BoxSwitch(p_sys, BOX_LOG);        return;
+    case 'P': BoxSwitch(p_sys, BOX_PLAYLIST);   return;
+    case 'B': BoxSwitch(p_sys, BOX_BROWSE);     return;
+    case 'x': BoxSwitch(p_sys, BOX_OBJECTS);    return;
+    case 'S': BoxSwitch(p_sys, BOX_STATS);      return;
 
     case '/': /* Search */
         p_sys->psz_search_chain[0] = '\0';
         p_sys->b_plidx_follow = false;
-        p_sys->i_before_search = p_sys->i_box_idx;
-        p_sys->i_box_type = BOX_SEARCH;
-        return true;
+        if (p_sys->i_box_type == BOX_PLAYLIST)
+        {
+            p_sys->i_before_search = p_sys->i_box_idx;
+            p_sys->i_box_type = BOX_SEARCH;
+        }
+        else
+        {
+            p_sys->i_before_search = 0;
+            BoxSwitch(p_sys, BOX_SEARCH);
+        }
+        return;
 
     case 'A': /* Open */
         p_sys->psz_open_chain[0] = '\0';
-        p_sys->i_box_type = BOX_OPEN;
-        return true;
+        if (p_sys->i_box_type == BOX_PLAYLIST)
+            p_sys->i_box_type = BOX_OPEN;
+        else
+            BoxSwitch(p_sys, BOX_OPEN);
+        return;
 
     /* Navigation */
-    case KEY_RIGHT: ChangePosition(p_intf, +0.01); return true;
-    case KEY_LEFT:  ChangePosition(p_intf, -0.01); return true;
+    case KEY_RIGHT: ChangePosition(p_intf, +0.01); return;
+    case KEY_LEFT:  ChangePosition(p_intf, -0.01); return;
 
     /* Common control */
     case 'f':
@@ -1663,16 +1666,16 @@ static bool HandleCommonKey(intf_thread_t *p_intf, int key)
                 vlc_object_release(p_vout);
             }
         }
-        return false;
+        return;
 
-    case ' ': PlayPause(p_intf);            return true;
-    case 's': playlist_Stop(p_playlist);    return true;
-    case 'e': Eject(p_intf);                return true;
+    case ' ': PlayPause(p_intf);            return;
+    case 's': playlist_Stop(p_playlist);    return;
+    case 'e': Eject(p_intf);                return;
 
-    case '[': InputNavigate(p_sys->p_input, "prev-title");      return true;
-    case ']': InputNavigate(p_sys->p_input, "next-title");      return true;
-    case '<': InputNavigate(p_sys->p_input, "prev-chapter");    return true;
-    case '>': InputNavigate(p_sys->p_input, "next-chapter");    return true;
+    case '[': InputNavigate(p_sys->p_input, "prev-title");      return;
+    case ']': InputNavigate(p_sys->p_input, "next-title");      return;
+    case '<': InputNavigate(p_sys->p_input, "prev-chapter");    return;
+    case '>': InputNavigate(p_sys->p_input, "next-chapter");    return;
 
     case 'p': playlist_Prev(p_playlist);            break;
     case 'n': playlist_Next(p_playlist);            break;
@@ -1684,11 +1687,11 @@ static bool HandleCommonKey(intf_thread_t *p_intf, int key)
         break;
 
     default:
-        return false;
+        return;
     }
 
     clear();
-    return true;
+    return;
 }
 
 static bool HandleListKey(intf_thread_t *p_intf, int key)
@@ -1699,6 +1702,8 @@ static bool HandleListKey(intf_thread_t *p_intf, int key)
     switch(key)
     {
 #ifdef __FreeBSD__
+/* workaround for FreeBSD + xterm:
+ * see http://www.nabble.com/curses-vs.-xterm-key-mismatch-t3574377.html */
     case KEY_SELECT:
 #endif
     case KEY_END:  p_sys->i_box_idx = p_sys->i_box_lines_total - 1; break;
@@ -1723,17 +1728,20 @@ static bool HandleListKey(intf_thread_t *p_intf, int key)
     return true;
 }
 
-static bool HandleKey(intf_thread_t *p_intf)
+static void HandleKey(intf_thread_t *p_intf)
 {
     intf_sys_t *p_sys = p_intf->p_sys;
     int key = getch();
     int box = p_sys->i_box_type;
 
     if (key == -1)
-        return false;
+        return;
 
     if (box == BOX_SEARCH || box == BOX_OPEN)
-        return HandleEditBoxKey(p_intf, key, p_sys->i_box_type);
+    {
+        HandleEditBoxKey(p_intf, key, p_sys->i_box_type);
+        return;
+    }
 
     if (box == BOX_NONE)
         switch(key)
@@ -1741,20 +1749,23 @@ static bool HandleKey(intf_thread_t *p_intf)
 #ifdef __FreeBSD__
         case KEY_SELECT:
 #endif
-        case KEY_END:   ChangePosition(p_intf, +.99);   return true;
-        case KEY_HOME:  ChangePosition(p_intf, -1.0);   return true;
-        case KEY_UP:    ChangePosition(p_intf, +0.05);  return true;
-        case KEY_DOWN:  ChangePosition(p_intf, -0.05);  return true;
-        default:        return HandleCommonKey(p_intf, key);
+        case KEY_END:   ChangePosition(p_intf, +.99);   return;
+        case KEY_HOME:  ChangePosition(p_intf, -1.0);   return;
+        case KEY_UP:    ChangePosition(p_intf, +0.05);  return;
+        case KEY_DOWN:  ChangePosition(p_intf, -0.05);  return;
+        default:        HandleCommonKey(p_intf, key);   return;
         }
 
     if (box == BOX_BROWSE   && HandleBrowseKey(p_intf, key))
-        return true;
+        return;
 
     if (box == BOX_PLAYLIST && HandlePlaylistKey(p_intf, key))
-        return true;
+        return;
+
+    if (HandleListKey(p_intf, key))
+        return;
 
-    return HandleListKey(p_intf, key) || HandleCommonKey(p_intf, key);
+    HandleCommonKey(p_intf, key);
 }
 
 /*
@@ -1781,6 +1792,19 @@ static void MsgCallback(msg_cb_data_t *data, msg_item_t *msg, unsigned i)
     vlc_restorecancel(canc);
 }
 
+static inline void UpdateInput(intf_sys_t *p_sys, playlist_t *p_playlist)
+{
+    if (!p_sys->p_input)
+    {
+        p_sys->p_input = playlist_CurrentInput(p_playlist);
+    }
+    else if (p_sys->p_input->b_dead)
+    {
+        vlc_object_release(p_sys->p_input);
+        p_sys->p_input = NULL;
+    }
+}
+
 /*****************************************************************************
  * Run: ncurses thread
  *****************************************************************************/
@@ -1789,36 +1813,18 @@ static void Run(intf_thread_t *p_intf)
     intf_sys_t    *p_sys = p_intf->p_sys;
     playlist_t    *p_playlist = pl_Get(p_intf);
 
-    time_t t_last_refresh;
     int canc = vlc_savecancel();
 
-    Redraw(p_intf, &t_last_refresh);
-
     var_AddCallback(p_playlist, "intf-change", PlaylistChanged, p_intf);
     var_AddCallback(p_playlist, "playlist-item-append", PlaylistChanged, p_intf);
 
-    while (vlc_object_alive(p_intf))
+    while (vlc_object_alive(p_intf) && !p_sys->b_exit)
     {
-        msleep(INTF_IDLE_SLEEP);
-
-        if (!p_sys->p_input)
-        {
-            p_sys->p_input = playlist_CurrentInput(p_playlist);
-            if (p_sys->p_input)
-                Redraw(p_intf, &t_last_refresh);
-        }
-        else if (p_sys->p_input->b_dead)
-        {
-            vlc_object_release(p_sys->p_input);
-            p_sys->p_input = NULL;
-        }
-
-        while (HandleKey(p_intf))
-            Redraw(p_intf, &t_last_refresh);
-
-        if ((time(0) - t_last_refresh) >= 1)
-            Redraw(p_intf, &t_last_refresh);
+        UpdateInput(p_sys, p_playlist);
+        Redraw(p_intf);
+        HandleKey(p_intf);
     }
+
     var_DelCallback(p_playlist, "intf-change", PlaylistChanged, p_intf);
     var_DelCallback(p_playlist, "playlist-item-append", PlaylistChanged, p_intf);
     vlc_restorecancel(canc);
@@ -1848,13 +1854,13 @@ static int Open(vlc_object_t *p_this)
     p_sys->i_msgs = 0;
     memset(p_sys->msgs, 0, sizeof p_sys->msgs);
     p_sys->p_sub = msg_Subscribe(p_intf->p_libvlc, MsgCallback, msg_cb_data);
+    msg_SubscriptionSetVerbosity(p_sys->p_sub,
+            var_GetInteger(p_intf->p_libvlc, "verbose"));
 
     p_sys->i_box_type = BOX_PLAYLIST;
     p_sys->b_plidx_follow = true;
     p_sys->b_color = var_CreateGetBool(p_intf, "color");
 
-    p_sys->category_view = true; //FIXME: switching back & forth is broken
-
     p_sys->psz_current_dir = var_CreateGetString(p_intf, "browse-dir");
     if (!p_sys->psz_current_dir || !*p_sys->psz_current_dir)
     {
@@ -1871,8 +1877,8 @@ static int Open(vlc_object_t *p_this)
     nonl();                 /* Take input chars one at a time */
     cbreak();               /* Don't echo */
     noecho();               /* Invisible cursor */
-    curs_set(0);            /* Non blocking wgetch() */
-    timeout(0);
+    curs_set(0);            /* Non blocking getch() */
+    timeout(1000);
     clear();
 
     /* Stop printing errors to the console */