1 /*****************************************************************************
2 * ncurses.c : NCurses interface for vlc
3 *****************************************************************************
4 * Copyright © 2001-2011 the VideoLAN team
6 * Authors: Sam Hocevar <sam@zoy.org>
7 * Laurent Aimar <fenrir@via.ecp.fr>
8 * Yoann Peronneau <yoann@videolan.org>
9 * Derk-Jan Hartman <hartman at videolan dot org>
10 * Rafaël Carré <funman@videolanorg>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /* UTF8 locale is required */
29 /*****************************************************************************
31 *****************************************************************************/
36 #define _XOPEN_SOURCE_EXTENDED 1
39 #include <stdatomic.h>
45 #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
46 #include <vlc_common.h>
47 #include <vlc_plugin.h>
51 #include <vlc_interface.h>
53 #include <vlc_charset.h>
54 #include <vlc_input_item.h>
56 #include <vlc_player.h>
57 #include <vlc_playlist.h>
61 #include <vlc_vector.h>
63 /*****************************************************************************
65 *****************************************************************************/
66 static int Open (vlc_object_t *);
67 static void Close (vlc_object_t *);
69 /*****************************************************************************
71 *****************************************************************************/
73 #define BROWSE_TEXT N_("Filebrowser starting point")
74 #define BROWSE_LONGTEXT N_(\
75 "This option allows you to specify the directory the ncurses filebrowser " \
76 "will show you initially.")
79 set_shortname("Ncurses")
80 set_description(N_("Ncurses interface"))
81 set_capability("interface", 10)
82 set_category(CAT_INTERFACE)
83 set_subcategory(SUBCAT_INTERFACE_MAIN)
84 set_callbacks(Open, Close)
85 add_shortcut("curses")
86 add_directory("browse-dir", NULL, BROWSE_TEXT, BROWSE_LONGTEXT)
91 /*****************************************************************************
92 * intf_sys_t: description and status of ncurses interface
93 *****************************************************************************/
108 static const char box_title[][19] = {
110 [BOX_HELP] = " Help ",
111 [BOX_INFO] = " Information ",
112 [BOX_LOG] = " Messages ",
113 [BOX_PLAYLIST] = " Playlist ",
114 [BOX_SEARCH] = " Playlist ",
115 [BOX_OPEN] = " Playlist ",
116 [BOX_BROWSE] = " Browse ",
117 [BOX_META] = " Meta-information ",
118 [BOX_STATS] = " Stats ",
136 /* XXX: new elements here ! */
141 /* Available colors: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE */
142 static const struct { short f; short b; } color_pairs[] =
144 /* element */ /* foreground*/ /* background*/
145 [C_TITLE] = { COLOR_YELLOW, COLOR_BLACK },
147 /* jamaican playlist, for rastafari sisters & brothers! */
148 [C_PLAYLIST_1] = { COLOR_GREEN, COLOR_BLACK },
149 [C_PLAYLIST_2] = { COLOR_YELLOW, COLOR_BLACK },
150 [C_PLAYLIST_3] = { COLOR_RED, COLOR_BLACK },
152 /* used in DrawBox() */
153 [C_BOX] = { COLOR_CYAN, COLOR_BLACK },
154 /* Source: State, Position, Volume, Chapters, etc...*/
155 [C_STATUS] = { COLOR_BLUE, COLOR_BLACK },
157 /* VLC messages, keep the order from highest priority to lowest */
158 [C_INFO] = { COLOR_BLACK, COLOR_WHITE },
159 [C_ERROR] = { COLOR_RED, COLOR_BLACK },
160 [C_WARNING] = { COLOR_YELLOW, COLOR_BLACK },
161 [C_DEBUG] = { COLOR_WHITE, COLOR_BLACK },
163 /* Category title: help, info, metadata */
164 [C_CATEGORY] = { COLOR_MAGENTA, COLOR_BLACK },
165 /* Folder (BOX_BROWSE) */
166 [C_FOLDER] = { COLOR_RED, COLOR_BLACK },
175 typedef struct VLC_VECTOR(char const *) pl_item_names;
184 /* rgb values for the color yellow */
190 int box_y; // start of box content
192 int box_lines_total; // number of lines in the box
193 int box_start; // first line of box displayed
194 int box_idx; // selected line
201 } msgs[50]; // ring buffer
204 vlc_mutex_t msg_lock;
206 /* Search Box context */
207 char search_chain[20];
209 /* Open Box Context */
212 /* File Browser context */
215 struct dir_entry_t **dir_entries;
216 bool show_hidden_files;
218 /* Playlist context */
219 vlc_playlist_t *playlist;
220 vlc_playlist_listener_id *playlist_listener;
221 pl_item_names pl_item_names;
226 /*****************************************************************************
228 *****************************************************************************/
230 static void DirsDestroy(intf_sys_t *sys)
232 while (sys->n_dir_entries) {
233 struct dir_entry_t *dir_entry = sys->dir_entries[--sys->n_dir_entries];
234 free(dir_entry->path);
237 free(sys->dir_entries);
238 sys->dir_entries = NULL;
241 static int comdir_entries(const void *a, const void *b)
243 struct dir_entry_t *dir_entry1 = *(struct dir_entry_t**)a;
244 struct dir_entry_t *dir_entry2 = *(struct dir_entry_t**)b;
246 if (dir_entry1->file == dir_entry2->file)
247 return strcasecmp(dir_entry1->path, dir_entry2->path);
249 return dir_entry1->file ? 1 : -1;
252 static bool IsFile(const char *current_dir, const char *entry)
257 if (asprintf(&uri, "%s" DIR_SEP "%s", current_dir, entry) != -1) {
259 ret = vlc_stat(uri, &st) || !S_ISDIR(st.st_mode);
266 static void ReadDir(intf_thread_t *intf)
268 intf_sys_t *sys = intf->p_sys;
270 if (!sys->current_dir || !*sys->current_dir) {
271 msg_Dbg(intf, "no current dir set");
275 DIR *current_dir = vlc_opendir(sys->current_dir);
277 msg_Warn(intf, "cannot open directory `%s' (%s)", sys->current_dir,
278 vlc_strerror_c(errno));
285 while ((entry = vlc_readdir(current_dir))) {
286 if (!sys->show_hidden_files && *entry == '.' && strcmp(entry, ".."))
289 struct dir_entry_t *dir_entry = malloc(sizeof *dir_entry);
290 if (unlikely(dir_entry == NULL))
293 dir_entry->file = IsFile(sys->current_dir, entry);
294 dir_entry->path = strdup(entry);
295 if (unlikely(dir_entry->path == NULL))
300 TAB_APPEND(sys->n_dir_entries, sys->dir_entries, dir_entry);
304 closedir(current_dir);
306 if (sys->n_dir_entries > 0)
307 qsort(sys->dir_entries, sys->n_dir_entries,
308 sizeof(struct dir_entry_t*), &comdir_entries);
311 /*****************************************************************************
312 * Adjust index position after a change (list navigation or item switching)
313 *****************************************************************************/
314 static void CheckIdx(intf_sys_t *sys)
316 int lines = sys->box_lines_total;
317 int height = LINES - sys->box_y - 2;
318 if (height > lines - 1)
321 /* make sure the new index is within the box */
322 if (sys->box_idx <= 0) {
325 } else if (sys->box_idx >= lines - 1 && lines > 0) {
326 sys->box_idx = lines - 1;
327 sys->box_start = sys->box_idx - height;
330 /* Fix box start (1st line of the box displayed) */
331 if (sys->box_idx < sys->box_start ||
332 sys->box_idx > height + sys->box_start + 1) {
333 sys->box_start = sys->box_idx - height/2;
334 if (sys->box_start < 0)
336 } else if (sys->box_idx == sys->box_start - 1) {
338 } else if (sys->box_idx == height + sys->box_start + 1) {
343 /*****************************************************************************
345 *****************************************************************************/
346 static void PlaylistRebuild(intf_thread_t *intf)
348 intf_sys_t *sys = intf->p_sys;
349 vlc_playlist_t *playlist = sys->playlist;
351 for (size_t i = 0; i < sys->pl_item_names.size; ++i)
352 free((void *)sys->pl_item_names.data[i]);
353 vlc_vector_clear(&sys->pl_item_names);
355 size_t count = vlc_playlist_Count(playlist);
356 if (!vlc_vector_reserve(&sys->pl_item_names, count))
358 for (size_t i = 0; i < count; ++i)
360 vlc_playlist_item_t *plitem = vlc_playlist_Get(playlist, i);
361 input_item_t *item = vlc_playlist_item_GetMedia(plitem);
362 char *name = input_item_GetTitleFbName(item);
363 vlc_vector_push(&sys->pl_item_names, name);
366 sys->need_update = false;
370 playlist_on_items_added(vlc_playlist_t *playlist,
372 vlc_playlist_item_t *const items[], size_t count,
375 VLC_UNUSED(playlist);
376 VLC_UNUSED(index); VLC_UNUSED(items); VLC_UNUSED(count);
378 intf_sys_t *sys = (intf_sys_t *)userdata;
379 sys->need_update = true;
383 playlist_on_items_updated(vlc_playlist_t *playlist,
385 vlc_playlist_item_t *const items[], size_t count,
388 VLC_UNUSED(playlist);
389 VLC_UNUSED(index); VLC_UNUSED(items); VLC_UNUSED(count);
391 ((intf_sys_t *)userdata)->need_update = true;
395 static int SubSearchPlaylist(intf_sys_t *sys, char *searchstring,
396 int i_start, int i_stop)
398 for (int i = i_start + 1; i < i_stop; i++)
399 if (strcasestr(sys->pl_item_names.data[i], searchstring))
404 static void SearchPlaylist(intf_sys_t *sys)
406 char *str = sys->search_chain;
407 int i_first = sys->box_idx;
414 int i_item = SubSearchPlaylist(sys, str, i_first + 1,
415 sys->pl_item_names.size);
417 i_item = SubSearchPlaylist(sys, str, 0, i_first);
420 sys->box_idx = i_item;
425 /****************************************************************************
427 ****************************************************************************/
429 static void start_color_and_pairs(intf_thread_t *intf)
431 intf_sys_t *sys = intf->p_sys;
435 msg_Warn(intf, "Terminal doesn't support colors");
440 for (int i = C_DEFAULT + 1; i < C_MAX; i++)
441 init_pair(i, color_pairs[i].f, color_pairs[i].b);
443 /* untested, in all my terminals, !can_change_color() --funman */
444 if (can_change_color()) {
445 color_content(COLOR_YELLOW, &sys->yellow_r, &sys->yellow_g, &sys->yellow_b);
446 init_color(COLOR_YELLOW, 960, 500, 0); /* YELLOW -> ORANGE */
450 static void DrawBox(int y, int h, bool color, const char *title)
453 if (w <= 3 || h <= 0)
456 if (color) color_set(C_BOX, NULL);
458 if (!title) title = "";
459 int len = strlen(title);
464 mvaddch(y, 0, ACS_ULCORNER);
465 mvhline(y, 1, ACS_HLINE, (w-len-2)/2);
466 mvprintw(y, 1+(w-len-2)/2, "%s", title);
467 mvhline(y, (w-len)/2+len, ACS_HLINE, w - 1 - ((w-len)/2+len));
468 mvaddch(y, w-1,ACS_URCORNER);
470 for (int i = 0; i < h; i++) {
471 mvaddch(++y, 0, ACS_VLINE);
472 mvaddch(y, w-1, ACS_VLINE);
475 mvaddch(++y, 0, ACS_LLCORNER);
476 mvhline(y, 1, ACS_HLINE, w - 2);
477 mvaddch(y, w-1, ACS_LRCORNER);
478 if (color) color_set(C_DEFAULT, NULL);
481 static void DrawEmptyLine(int y, int x, int w)
485 mvhline(y, x, ' ', w);
488 static void DrawLine(int y, int x, int w)
493 mvhline(y, x, ' ', w);
497 static void mvnprintw(int y, int x, int w, const char *p_fmt, ...)
506 va_start(vl_args, p_fmt);
507 int i_ret = vasprintf(&p_buf, p_fmt, vl_args);
515 wchar_t wide[len + 1];
518 size_t i_char_len = mbstowcs(wide, p_buf, len);
520 size_t i_width; /* number of columns */
522 if (i_char_len == (size_t)-1) /* an invalid character was encountered */ {
527 i_width = wcswidth(wide, i_char_len);
528 if (i_width == (size_t)-1) {
529 /* a non printable character was encountered */
531 for (unsigned i = 0 ; i < i_char_len ; i++) {
532 int i_cwidth = wcwidth(wide[i]);
538 if (i_width <= (size_t)w) {
539 mvprintw(y, x, "%s", p_buf);
540 mvhline(y, x + i_width, ' ', w - i_width);
545 int i_total_width = 0;
547 while (i_total_width < w) {
548 i_total_width += wcwidth(wide[i]);
549 if (w > 7 && i_total_width >= w/2) {
552 i_total_width -= wcwidth(wide[i]) - 2;
554 /* we require this check only if at least one character
555 * 4 or more columns wide exists (which i doubt) */
557 i_total_width -= wcwidth(wide[i-1]) - 1;
560 /* find the widest string */
561 int j, i_2nd_width = 0;
562 for (j = i_char_len - 1; i_2nd_width < w - i_total_width; j--)
563 i_2nd_width += wcwidth(wide[j]);
565 /* we already have i_total_width columns filled, and we can't
566 * have more than w columns */
567 if (i_2nd_width > w - i_total_width)
570 wmemmove(&wide[i+2], &wide[j+1], i_char_len - j - 1);
571 wide[i + 2 + i_char_len - j - 1] = '\0';
576 if (w <= 7) /* we don't add the '...' else we lose too much chars */
579 size_t i_wlen = wcslen(wide) * 6 + 1; /* worst case */
580 char ellipsized[i_wlen];
581 wcstombs(ellipsized, wide, i_wlen);
582 mvprintw(y, x, "%s", ellipsized);
587 static void MainBoxWrite(intf_sys_t *sys, int l, const char *p_fmt, ...)
591 bool b_selected = l == sys->box_idx;
593 if (l < sys->box_start || l - sys->box_start >= sys->box_height)
596 va_start(vl_args, p_fmt);
597 int i_ret = vasprintf(&p_buf, p_fmt, vl_args);
602 if (b_selected) attron(A_REVERSE);
603 mvnprintw(sys->box_y + l - sys->box_start, 1, COLS - 2, "%s", p_buf);
604 if (b_selected) attroff(A_REVERSE);
609 static int DrawMeta(intf_thread_t *intf)
611 intf_sys_t *sys = intf->p_sys;
614 vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
615 vlc_player_Lock(player);
616 input_item_t *item = vlc_player_HoldCurrentMedia(player);
617 vlc_player_Unlock(player);
621 vlc_mutex_lock(&item->lock);
622 for (int i=0; i<VLC_META_TYPE_COUNT; i++) {
623 const char *meta = vlc_meta_Get(item->p_meta, i);
627 if (sys->color) color_set(C_CATEGORY, NULL);
628 MainBoxWrite(sys, l++, " [%s]", vlc_meta_TypeToLocalizedString(i));
629 if (sys->color) color_set(C_DEFAULT, NULL);
630 MainBoxWrite(sys, l++, " %s", meta);
632 vlc_mutex_unlock(&item->lock);
634 input_item_Release(item);
639 static int DrawInfo(intf_thread_t *intf)
641 intf_sys_t *sys = intf->p_sys;
644 vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
645 vlc_player_Lock(player);
646 input_item_t *item = vlc_player_HoldCurrentMedia(player);
647 vlc_player_Unlock(player);
651 vlc_mutex_lock(&item->lock);
652 for (int i = 0; i < item->i_categories; i++) {
653 info_category_t *p_category = item->pp_categories[i];
656 if (sys->color) color_set(C_CATEGORY, NULL);
657 MainBoxWrite(sys, l++, _(" [%s]"), p_category->psz_name);
658 if (sys->color) color_set(C_DEFAULT, NULL);
659 info_foreach(p_info, &p_category->infos)
660 MainBoxWrite(sys, l++, _(" %s: %s"),
661 p_info->psz_name, p_info->psz_value);
663 vlc_mutex_unlock(&item->lock);
665 input_item_Release(item);
670 static int DrawStats(intf_thread_t *intf)
672 intf_sys_t *sys = intf->p_sys;
673 input_stats_t *p_stats;
674 int l = 0, i_audio = 0, i_video = 0;
676 vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
677 vlc_player_Lock(player);
678 input_item_t *item = vlc_player_HoldCurrentMedia(player);
679 vlc_player_Unlock(player);
683 vlc_mutex_lock(&item->lock);
684 p_stats = item->p_stats;
686 for (int i = 0; i < item->i_es ; i++) {
687 i_audio += (item->es[i]->i_cat == AUDIO_ES);
688 i_video += (item->es[i]->i_cat == VIDEO_ES);
692 if (sys->color) color_set(C_CATEGORY, NULL);
693 MainBoxWrite(sys, l++, _("+-[Incoming]"));
694 if (sys->color) color_set(C_DEFAULT, NULL);
695 MainBoxWrite(sys, l++, _("| input bytes read : %8.0f KiB"),
696 (float)(p_stats->i_read_bytes)/1024);
697 MainBoxWrite(sys, l++, _("| input bitrate : %6.0f kb/s"),
698 p_stats->f_input_bitrate*8000);
699 MainBoxWrite(sys, l++, _("| demux bytes read : %8.0f KiB"),
700 (float)(p_stats->i_demux_read_bytes)/1024);
701 MainBoxWrite(sys, l++, _("| demux bitrate : %6.0f kb/s"),
702 p_stats->f_demux_bitrate*8000);
706 if (sys->color) color_set(C_CATEGORY, NULL);
707 MainBoxWrite(sys, l++, _("+-[Video Decoding]"));
708 if (sys->color) color_set(C_DEFAULT, NULL);
709 MainBoxWrite(sys, l++, _("| video decoded : %5"PRIi64),
710 p_stats->i_decoded_video);
711 MainBoxWrite(sys, l++, _("| frames displayed : %5"PRIi64),
712 p_stats->i_displayed_pictures);
713 MainBoxWrite(sys, l++, _("| frames late : %5"PRIi64),
714 p_stats->i_late_pictures);
715 MainBoxWrite(sys, l++, _("| frames lost : %5"PRIi64),
716 p_stats->i_lost_pictures);
720 if (sys->color) color_set(C_CATEGORY, NULL);
721 MainBoxWrite(sys, l++, _("+-[Audio Decoding]"));
722 if (sys->color) color_set(C_DEFAULT, NULL);
723 MainBoxWrite(sys, l++, _("| audio decoded : %5"PRIi64),
724 p_stats->i_decoded_audio);
725 MainBoxWrite(sys, l++, _("| buffers played : %5"PRIi64),
726 p_stats->i_played_abuffers);
727 MainBoxWrite(sys, l++, _("| buffers lost : %5"PRIi64),
728 p_stats->i_lost_abuffers);
730 if (sys->color) color_set(C_DEFAULT, NULL);
732 vlc_mutex_unlock(&item->lock);
734 input_item_Release(item);
739 static int DrawHelp(intf_thread_t *intf)
741 intf_sys_t *sys = intf->p_sys;
744 #define H(a) MainBoxWrite(sys, l++, a)
746 if (sys->color) color_set(C_CATEGORY, NULL);
748 if (sys->color) color_set(C_DEFAULT, NULL);
749 H(_(" h,H Show/Hide help box"));
750 H(_(" i Show/Hide info box"));
751 H(_(" M Show/Hide metadata box"));
752 H(_(" L Show/Hide messages box"));
753 H(_(" P Show/Hide playlist box"));
754 H(_(" B Show/Hide filebrowser"));
755 H(_(" S Show/Hide statistics box"));
756 H(_(" Esc Close Add/Search entry"));
757 H(_(" Ctrl-l Refresh the screen"));
760 if (sys->color) color_set(C_CATEGORY, NULL);
762 if (sys->color) color_set(C_DEFAULT, NULL);
763 H(_(" q, Q, Esc Quit"));
765 H(_(" <space> Pause/Play"));
766 H(_(" f Toggle Fullscreen"));
767 H(_(" c Cycle through audio tracks"));
768 H(_(" v Cycle through subtitles tracks"));
769 H(_(" b Cycle through video tracks"));
770 H(_(" n, p Next/Previous playlist item"));
771 H(_(" [, ] Next/Previous title"));
772 H(_(" <, > Next/Previous chapter"));
773 /* xgettext: You can use ← and → characters */
774 H(_(" <left>,<right> Seek -/+ 1%%"));
775 H(_(" a, z Volume Up/Down"));
777 /* xgettext: You can use ↑ and ↓ characters */
778 H(_(" <up>,<down> Navigate through the box line by line"));
779 /* xgettext: You can use ⇞ and ⇟ characters */
780 H(_(" <pageup>,<pagedown> Navigate through the box page by page"));
781 /* xgettext: You can use ↖ and ↘ characters */
782 H(_(" <start>,<end> Navigate to start/end of box"));
785 if (sys->color) color_set(C_CATEGORY, NULL);
787 if (sys->color) color_set(C_DEFAULT, NULL);
788 H(_(" r Toggle Random playing"));
789 H(_(" l Toggle Loop Playlist"));
790 H(_(" R Toggle Repeat item"));
791 H(_(" o Order Playlist by title"));
792 H(_(" O Reverse order Playlist by title"));
793 H(_(" g Go to the current playing item"));
794 H(_(" / Look for an item"));
795 H(_(" ; Look for the next item"));
796 H(_(" A Add an entry"));
797 /* xgettext: You can use ⌫ character to translate <backspace> */
798 H(_(" D, <backspace>, <del> Delete an entry"));
799 H(_(" e Eject (if stopped)"));
802 if (sys->color) color_set(C_CATEGORY, NULL);
803 H(_("[Filebrowser]"));
804 if (sys->color) color_set(C_DEFAULT, NULL);
805 H(_(" <enter> Add the selected file to the playlist"));
806 H(_(" <space> Add the selected directory to the playlist"));
807 H(_(" . Show/Hide hidden files"));
810 if (sys->color) color_set(C_CATEGORY, NULL);
812 if (sys->color) color_set(C_DEFAULT, NULL);
813 /* xgettext: You can use ↑ and ↓ characters */
814 H(_(" <up>,<down> Seek +/-5%%"));
820 static int DrawBrowse(intf_thread_t *intf)
822 intf_sys_t *sys = intf->p_sys;
824 for (int i = 0; i < sys->n_dir_entries; i++) {
825 struct dir_entry_t *dir_entry = sys->dir_entries[i];
826 char type = dir_entry->file ? ' ' : '+';
829 color_set(dir_entry->file ? C_DEFAULT : C_FOLDER, NULL);
830 MainBoxWrite(sys, i, " %c %s", type, dir_entry->path);
833 return sys->n_dir_entries;
836 static int DrawPlaylist(intf_thread_t *intf)
838 intf_sys_t *sys = intf->p_sys;
839 vlc_playlist_t *playlist = sys->playlist;
841 vlc_playlist_Lock(playlist);
842 ssize_t cur_idx = vlc_playlist_GetCurrentIndex(playlist);
843 if (sys->need_update)
844 PlaylistRebuild(intf);
845 vlc_playlist_Unlock(playlist);
847 if (sys->plidx_follow)
848 sys->box_idx = cur_idx == -1 ? 0 : cur_idx;
850 for (size_t i = 0; i < sys->pl_item_names.size; i++)
853 color_set(i%3 + C_PLAYLIST_1, NULL);
855 MainBoxWrite(sys, i, "%c %s",
856 (ssize_t)i == cur_idx ? '>' : ' ',
857 sys->pl_item_names.data[i]);
860 color_set(C_DEFAULT, NULL);
863 return sys->pl_item_names.size;
866 static int DrawMessages(intf_thread_t *intf)
868 intf_sys_t *sys = intf->p_sys;
871 vlc_mutex_lock(&sys->msg_lock);
874 vlc_log_t *msg = sys->msgs[i].item;
877 color_set(sys->msgs[i].type + C_INFO, NULL);
878 MainBoxWrite(sys, l++, "[%s] %s", msg->psz_module, sys->msgs[i].msg);
881 if (++i == sizeof sys->msgs / sizeof *sys->msgs)
884 if (i == sys->i_msgs) /* did we loop around the ring buffer ? */
888 vlc_mutex_unlock(&sys->msg_lock);
890 color_set(C_DEFAULT, NULL);
895 static int DrawStatus(intf_thread_t *intf)
897 intf_sys_t *sys = intf->p_sys;
898 vlc_playlist_t *playlist = sys->playlist;
899 const char *name = _("VLC media player");
900 const size_t name_len = strlen(name) + sizeof(PACKAGE_VERSION);
902 const char *repeat, *loop, *random;
906 int padding = COLS - name_len; /* center title */
911 if (sys->color) color_set(C_TITLE, NULL);
912 DrawEmptyLine(y, 0, COLS);
913 mvnprintw(y++, padding / 2, COLS, "%s %s", name, PACKAGE_VERSION);
914 if (sys->color) color_set(C_STATUS, NULL);
917 y++; /* leave a blank line */
922 vlc_playlist_Lock(playlist);
923 enum vlc_playlist_playback_repeat repeat_mode =
924 vlc_playlist_GetPlaybackRepeat(playlist);
925 enum vlc_playlist_playback_order order_mode =
926 vlc_playlist_GetPlaybackOrder(playlist);
927 if (repeat_mode == VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT)
929 else if (repeat_mode == VLC_PLAYLIST_PLAYBACK_REPEAT_ALL)
931 if (order_mode == VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM)
934 vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
935 if (vlc_player_IsStarted(player)) {
938 input_item_t *item = vlc_player_GetCurrentMedia(player);
940 uri = input_item_GetURI(item);
941 path = vlc_uri2path(uri);
943 mvnprintw(y++, 0, COLS, _(" Source : %s"), path?path:uri);
947 enum vlc_player_state state = vlc_player_GetState(player);
950 static const char *input_state[] = {
951 [VLC_PLAYER_STATE_PLAYING] = " State : Playing %s%s%s",
952 [VLC_PLAYER_STATE_STARTED] = " State : Opening/Connecting %s%s%s",
953 [VLC_PLAYER_STATE_PAUSED] = " State : Paused %s%s%s",
955 char buf1[MSTRTIME_MAX_SIZE];
956 char buf2[MSTRTIME_MAX_SIZE];
959 case VLC_PLAYER_STATE_STOPPED:
963 case VLC_PLAYER_STATE_PLAYING:
964 case VLC_PLAYER_STATE_STARTED:
965 case VLC_PLAYER_STATE_PAUSED:
966 mvnprintw(y++, 0, COLS, _(input_state[state]), repeat, random, loop);
970 secstotimestr(buf1, SEC_FROM_VLC_TICK(vlc_player_GetTime(player)));
971 secstotimestr(buf2, SEC_FROM_VLC_TICK(vlc_player_GetLength(player)));
973 mvnprintw(y++, 0, COLS, _(" Position : %s/%s"), buf1, buf2);
975 volume = vlc_player_aout_GetVolume(player);
976 bool mute = vlc_player_aout_IsMuted(player);
977 mvnprintw(y++, 0, COLS,
978 mute ? _(" Volume : Mute") :
979 volume >= 0.f ? _(" Volume : %3ld%%") : _(" Volume : ----"),
980 lroundf(volume * 100.f));
982 size_t title_count = 0;
983 struct vlc_player_title_list *titles =
984 vlc_player_GetTitleList(player);
986 title_count = vlc_player_title_list_GetCount(titles);
988 mvnprintw(y++, 0, COLS, _(" Title : %zd/%d"),
989 vlc_player_GetSelectedTitleIdx(player), title_count);
990 struct vlc_player_title const *title =
991 vlc_player_GetSelectedTitle(player);
993 if (title && title->chapter_count > 0)
994 mvnprintw(y++, 0, COLS, _(" Chapter : %zd/%d"),
995 vlc_player_GetSelectedChapterIdx(player),
996 title->chapter_count);
998 if (vlc_player_GetError(player) == VLC_PLAYER_ERROR_GENERIC)
1001 mvnprintw(y++, 0, COLS, _(" Source: <no current item>"));
1002 mvnprintw(y++, 0, COLS, " %s%s%s", repeat, random, loop);
1003 mvnprintw(y++, 0, COLS, _(" [ h for help ]"));
1004 DrawEmptyLine(y++, 0, COLS);
1007 if (sys->color) color_set(C_DEFAULT, NULL);
1008 DrawBox(y++, 1, sys->color, ""); /* position slider */
1009 DrawEmptyLine(y, 1, COLS-2);
1010 if (vlc_player_IsStarted(player))
1011 DrawLine(y, 1, (int)((COLS-2) * vlc_player_GetPosition(player)));
1012 y += 2; /* skip slider and box */
1014 vlc_playlist_Unlock(playlist);
1019 static void FillTextBox(intf_sys_t *sys)
1021 int width = COLS - 2;
1023 DrawEmptyLine(7, 1, width);
1024 if (sys->box_type == BOX_OPEN)
1025 mvnprintw(7, 1, width, _("Open: %s"), sys->open_chain);
1027 mvnprintw(7, 1, width, _("Find: %s"), sys->search_chain);
1030 static void FillBox(intf_thread_t *intf)
1032 intf_sys_t *sys = intf->p_sys;
1033 static int (* const draw[]) (intf_thread_t *) = {
1034 [BOX_HELP] = DrawHelp,
1035 [BOX_INFO] = DrawInfo,
1036 [BOX_META] = DrawMeta,
1037 [BOX_STATS] = DrawStats,
1038 [BOX_BROWSE] = DrawBrowse,
1039 [BOX_PLAYLIST] = DrawPlaylist,
1040 [BOX_SEARCH] = DrawPlaylist,
1041 [BOX_OPEN] = DrawPlaylist,
1042 [BOX_LOG] = DrawMessages,
1045 sys->box_lines_total = draw[sys->box_type](intf);
1047 if (sys->box_type == BOX_SEARCH || sys->box_type == BOX_OPEN)
1051 static void Redraw(intf_thread_t *intf)
1053 intf_sys_t *sys = intf->p_sys;
1054 int box = sys->box_type;
1055 int y = DrawStatus(intf);
1057 sys->box_height = LINES - y - 2;
1058 DrawBox(y++, sys->box_height, sys->color, _(box_title[box]));
1062 if (box != BOX_NONE) {
1065 if (sys->box_lines_total == 0)
1067 else if (sys->box_start > sys->box_lines_total - 1)
1068 sys->box_start = sys->box_lines_total - 1;
1069 y += __MIN(sys->box_lines_total - sys->box_start,
1073 while (y < LINES - 1)
1074 DrawEmptyLine(y++, 1, COLS - 2);
1079 static void ChangePosition(vlc_player_t *player, float increment)
1081 vlc_player_Lock(player);
1082 if (vlc_player_GetState(player) == VLC_PLAYER_STATE_PLAYING)
1083 vlc_player_JumpPos(player, increment);
1084 vlc_player_Unlock(player);
1087 static inline void RemoveLastUTF8Entity(char *psz, int len)
1089 while (len && ((psz[--len] & 0xc0) == 0x80)) /* UTF8 continuation byte */
1094 static char *GetDiscDevice(const char *name)
1096 static const struct { const char *s; size_t n; const char *v; } devs[] =
1098 { "cdda://", 7, "cd-audio", },
1099 { "dvd://", 6, "dvd", },
1100 { "vcd://", 6, "vcd", },
1104 for (unsigned i = 0; i < sizeof devs / sizeof *devs; i++) {
1105 size_t n = devs[i].n;
1106 if (!strncmp(name, devs[i].s, n)) {
1107 if (name[n] == '@' || name[n] == '\0')
1108 return config_GetPsz(devs[i].v);
1109 /* Omit the beginning MRL-selector characters */
1110 return strdup(name + n);
1114 device = strdup(name);
1116 if (device) /* Remove what we have after @ */
1117 device[strcspn(device, "@")] = '\0';
1122 static void Eject(intf_thread_t *intf, vlc_player_t *player)
1124 char *device, *name;
1126 /* If there's a stream playing, we aren't allowed to eject ! */
1127 vlc_player_Lock(player);
1128 bool started = vlc_player_IsStarted(player);
1129 vlc_player_Unlock(player);
1133 vlc_player_Lock(player);
1134 input_item_t *current = vlc_player_GetCurrentMedia(player);
1135 vlc_player_Unlock(player);
1138 name = current->psz_name;
1139 device = name ? GetDiscDevice(name) : NULL;
1142 intf_Eject(intf, device);
1147 static void AddItem(intf_thread_t *intf, const char *path)
1149 char *uri = vlc_path2uri(path, NULL);
1153 input_item_t *item = input_item_New(uri, NULL);
1155 if (unlikely(item == NULL))
1158 intf_sys_t *sys = intf->p_sys;
1159 vlc_playlist_t *playlist = sys->playlist;
1160 vlc_playlist_Lock(playlist);
1161 vlc_playlist_AppendOne(playlist, item);
1162 vlc_playlist_Unlock(playlist);
1164 input_item_Release(item);
1167 static inline void BoxSwitch(intf_sys_t *sys, int box)
1169 sys->box_type = (sys->box_type == box) ? BOX_NONE : box;
1174 static bool HandlePlaylistKey(intf_thread_t *intf, int key)
1176 intf_sys_t *sys = intf->p_sys;
1177 vlc_playlist_t *playlist = sys->playlist;
1181 /* Playlist Settings */
1183 vlc_playlist_Lock(playlist);
1184 enum vlc_playlist_playback_order order_mode =
1185 vlc_playlist_GetPlaybackOrder(playlist);
1187 order_mode == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL
1188 ? VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM
1189 : VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL;
1190 vlc_playlist_SetPlaybackOrder(playlist, order_mode);
1191 vlc_playlist_Unlock(playlist);
1195 vlc_playlist_Lock(playlist);
1196 enum vlc_playlist_playback_repeat repeat_mode =
1197 vlc_playlist_GetPlaybackRepeat(playlist);
1198 switch (repeat_mode)
1200 case VLC_PLAYLIST_PLAYBACK_REPEAT_NONE:
1201 repeat_mode = key == 'l'
1202 ? VLC_PLAYLIST_PLAYBACK_REPEAT_ALL
1203 : VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT;
1205 case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
1206 repeat_mode = key == 'l'
1207 ? VLC_PLAYLIST_PLAYBACK_REPEAT_NONE
1208 : VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT;
1210 case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
1211 repeat_mode = key == 'l'
1212 ? VLC_PLAYLIST_PLAYBACK_REPEAT_ALL
1213 : VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;
1216 vlc_playlist_SetPlaybackRepeat(playlist, repeat_mode);
1217 vlc_playlist_Unlock(playlist);
1223 vlc_playlist_Lock(playlist);
1224 struct vlc_playlist_sort_criterion criteria =
1226 .key = VLC_PLAYLIST_SORT_KEY_TITLE,
1228 ? VLC_PLAYLIST_SORT_ORDER_ASCENDING
1229 : VLC_PLAYLIST_SORT_ORDER_DESCENDING
1231 vlc_playlist_Sort(playlist, &criteria, 1);
1232 sys->need_update = true;
1233 vlc_playlist_Unlock(playlist);
1237 SearchPlaylist(sys);
1241 vlc_playlist_Lock(playlist);
1242 sys->box_idx = vlc_playlist_GetCurrentIndex(playlist);
1243 vlc_playlist_Unlock(playlist);
1244 sys->plidx_follow = true;
1252 if (sys->pl_item_names.size)
1254 vlc_playlist_Lock(playlist);
1255 vlc_playlist_RemoveOne(playlist, sys->box_idx);
1256 if (sys->box_idx >= sys->box_lines_total - 1)
1257 sys->box_idx = sys->box_lines_total - 2;
1258 sys->need_update = true;
1259 vlc_playlist_Unlock(playlist);
1266 if (sys->pl_item_names.size)
1268 vlc_playlist_Lock(playlist);
1269 vlc_playlist_PlayAt(playlist, sys->box_idx);
1270 vlc_playlist_Unlock(playlist);
1271 sys->plidx_follow = true;
1279 static bool HandleBrowseKey(intf_thread_t *intf, int key)
1281 intf_sys_t *sys = intf->p_sys;
1282 struct dir_entry_t *dir_entry;
1287 sys->show_hidden_files = !sys->show_hidden_files;
1295 dir_entry = sys->dir_entries[sys->box_idx];
1297 if (asprintf(&path, "%s" DIR_SEP "%s", sys->current_dir,
1298 dir_entry->path) == -1)
1301 if (!dir_entry->file && key != ' ') {
1302 free(sys->current_dir);
1303 sys->current_dir = path;
1311 AddItem(intf, path);
1313 BoxSwitch(sys, BOX_PLAYLIST);
1320 static void OpenSelection(intf_thread_t *intf)
1322 intf_sys_t *sys = intf->p_sys;
1324 AddItem(intf, sys->open_chain);
1325 sys->plidx_follow = true;
1328 static void HandleEditBoxKey(intf_thread_t *intf, int key, int box)
1330 intf_sys_t *sys = intf->p_sys;
1331 bool search = box == BOX_SEARCH;
1332 char *str = search ? sys->search_chain: sys->open_chain;
1333 size_t len = strlen(str);
1335 assert(box == BOX_SEARCH || box == BOX_OPEN);
1340 case KEY_CLEAR: clear(); return;
1346 SearchPlaylist(sys);
1348 OpenSelection(intf);
1350 sys->box_type = BOX_PLAYLIST;
1353 case 0x1b: /* ESC */
1354 /* Alt+key combinations return 2 keys in the terminal keyboard:
1355 * ESC, and the 2nd key.
1356 * If some other key is available immediately (where immediately
1357 * means after getch() 1 second delay), that means that the
1358 * ESC key was not pressed.
1360 * man 3X curs_getch says:
1362 * Use of the escape key by a programmer for a single
1363 * character function is discouraged, as it will cause a delay
1364 * of up to one second while the keypad code looks for a
1365 * following function-key sequence.
1369 sys->box_type = BOX_PLAYLIST;
1374 RemoveLastUTF8Entity(str, len);
1378 if (len + 1 < (search ? sizeof sys->search_chain
1379 : sizeof sys->open_chain)) {
1381 str[len + 1] = '\0';
1386 SearchPlaylist(sys);
1389 static void HandleCommonKey(intf_thread_t *intf, vlc_player_t *player, int key)
1391 intf_sys_t *sys = intf->p_sys;
1392 vlc_playlist_t *playlist = sys->playlist;
1396 case 0x1b: /* ESC */
1397 /* See comment in HandleEditBoxKey() */
1405 libvlc_Quit(vlc_object_instance(intf));
1409 case 'H': BoxSwitch(sys, BOX_HELP); return;
1410 case 'i': BoxSwitch(sys, BOX_INFO); return;
1411 case 'M': BoxSwitch(sys, BOX_META); return;
1412 case 'L': BoxSwitch(sys, BOX_LOG); return;
1413 case 'P': BoxSwitch(sys, BOX_PLAYLIST); return;
1414 case 'B': BoxSwitch(sys, BOX_BROWSE); return;
1415 case 'S': BoxSwitch(sys, BOX_STATS); return;
1417 case '/': /* Search */
1418 sys->plidx_follow = false;
1419 BoxSwitch(sys, BOX_SEARCH);
1422 case 'A': /* Open */
1423 sys->open_chain[0] = '\0';
1424 BoxSwitch(sys, BOX_OPEN);
1428 case KEY_RIGHT: ChangePosition(player, +0.01); return;
1429 case KEY_LEFT: ChangePosition(player, -0.01); return;
1431 /* Common control */
1433 vlc_player_vout_ToggleFullscreen(player);
1437 vlc_player_Lock(player);
1438 vlc_player_TogglePause(player);
1439 vlc_player_Unlock(player);
1442 vlc_player_Lock(player);
1443 vlc_player_Stop(player);
1444 vlc_player_Unlock(player);
1447 case 'e': Eject(intf, player); return;
1450 vlc_player_Lock(player);
1451 vlc_player_SelectPrevTitle(player);
1452 vlc_player_Unlock(player);
1455 vlc_player_Lock(player);
1456 vlc_player_SelectNextTitle(player);
1457 vlc_player_Unlock(player);
1460 vlc_player_Lock(player);
1461 vlc_player_SelectPrevChapter(player);
1462 vlc_player_Unlock(player);
1465 vlc_player_Lock(player);
1466 vlc_player_SelectNextChapter(player);
1467 vlc_player_Unlock(player);
1471 vlc_playlist_Lock(playlist);
1472 vlc_playlist_Prev(playlist);
1473 vlc_playlist_Unlock(playlist);
1476 vlc_playlist_Lock(playlist);
1477 vlc_playlist_Next(playlist);
1478 vlc_playlist_Unlock(playlist);
1482 vlc_player_Lock(player);
1483 vlc_player_aout_IncrementVolume(player, 1, NULL);
1484 vlc_player_Unlock(player);
1487 vlc_player_Lock(player);
1488 vlc_player_aout_DecrementVolume(player, 1, NULL);
1489 vlc_player_Unlock(player);
1492 vlc_player_Lock(player);
1493 vlc_player_aout_ToggleMute(player);
1494 vlc_player_Unlock(player);
1498 vlc_player_Lock(player);
1499 vlc_player_SelectNextTrack(player, AUDIO_ES);
1500 vlc_player_Unlock(player);
1503 vlc_player_Lock(player);
1504 vlc_player_SelectNextTrack(player, SPU_ES);
1505 vlc_player_Unlock(player);
1508 vlc_player_Lock(player);
1509 vlc_player_SelectNextTrack(player, VIDEO_ES);
1510 vlc_player_Unlock(player);
1525 static bool HandleListKey(intf_thread_t *intf, int key)
1527 intf_sys_t *sys = intf->p_sys;
1528 vlc_playlist_t *playlist = sys->playlist;
1533 /* workaround for FreeBSD + xterm:
1534 * see http://www.nabble.com/curses-vs.-xterm-key-mismatch-t3574377.html */
1537 case KEY_END: sys->box_idx = sys->box_lines_total - 1; break;
1538 case KEY_HOME: sys->box_idx = 0; break;
1539 case KEY_UP: sys->box_idx--; break;
1540 case KEY_DOWN: sys->box_idx++; break;
1541 case KEY_PPAGE:sys->box_idx -= sys->box_height; break;
1542 case KEY_NPAGE:sys->box_idx += sys->box_height; break;
1549 if (sys->box_type == BOX_PLAYLIST) {
1550 vlc_playlist_Lock(playlist);
1552 sys->box_idx == vlc_playlist_GetCurrentIndex(playlist);
1553 vlc_playlist_Unlock(playlist);
1559 static void HandleKey(intf_thread_t *intf)
1561 intf_sys_t *sys = intf->p_sys;
1563 int box = sys->box_type;
1565 vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
1570 if (box == BOX_SEARCH || box == BOX_OPEN) {
1571 HandleEditBoxKey(intf, key, sys->box_type);
1575 if (box == BOX_NONE)
1581 case KEY_END: ChangePosition(player, +.99); return;
1582 case KEY_HOME: ChangePosition(player, -1.0); return;
1583 case KEY_UP: ChangePosition(player, +0.05); return;
1584 case KEY_DOWN: ChangePosition(player, -0.05); return;
1585 default: HandleCommonKey(intf, player, key); return;
1588 if (box == BOX_BROWSE && HandleBrowseKey(intf, key))
1591 if (box == BOX_PLAYLIST && HandlePlaylistKey(intf, key))
1594 if (HandleListKey(intf, key))
1597 HandleCommonKey(intf, player, key);
1603 static vlc_log_t *msg_Copy (const vlc_log_t *msg)
1605 vlc_log_t *copy = (vlc_log_t *)xmalloc (sizeof (*copy));
1606 copy->i_object_id = msg->i_object_id;
1607 copy->psz_object_type = msg->psz_object_type;
1608 copy->psz_module = strdup (msg->psz_module);
1609 copy->psz_header = msg->psz_header ? strdup (msg->psz_header) : NULL;
1613 static void msg_Free (vlc_log_t *msg)
1615 free ((char *)msg->psz_module);
1616 free ((char *)msg->psz_header);
1620 static void MsgCallback(void *data, int type, const vlc_log_t *msg,
1621 const char *format, va_list ap)
1623 intf_sys_t *sys = data;
1626 if (sys->verbosity < 0
1627 || sys->verbosity < (type - VLC_MSG_ERR)
1628 || vasprintf(&text, format, ap) == -1)
1631 vlc_mutex_lock(&sys->msg_lock);
1633 sys->msgs[sys->i_msgs].type = type;
1634 if (sys->msgs[sys->i_msgs].item != NULL)
1635 msg_Free(sys->msgs[sys->i_msgs].item);
1636 sys->msgs[sys->i_msgs].item = msg_Copy(msg);
1637 free(sys->msgs[sys->i_msgs].msg);
1638 sys->msgs[sys->i_msgs].msg = text;
1640 if (++sys->i_msgs == (sizeof sys->msgs / sizeof *sys->msgs))
1643 vlc_mutex_unlock(&sys->msg_lock);
1646 static const struct vlc_logger_operations log_ops = { MsgCallback, NULL };
1648 /*****************************************************************************
1649 * Run: ncurses thread
1650 *****************************************************************************/
1651 static void *Run(void *data)
1653 intf_thread_t *intf = data;
1654 intf_sys_t *sys = intf->p_sys;
1656 while (atomic_load_explicit(&sys->alive, memory_order_relaxed)) {
1663 /*****************************************************************************
1664 * Open: initialize and create window
1665 *****************************************************************************/
1666 static int Open(vlc_object_t *p_this)
1668 intf_thread_t *intf = (intf_thread_t *)p_this;
1669 intf_sys_t *sys = intf->p_sys = calloc(1, sizeof(intf_sys_t));
1674 atomic_init(&sys->alive, true);
1675 vlc_mutex_init(&sys->msg_lock);
1677 sys->verbosity = var_InheritInteger(intf, "verbose");
1678 vlc_LogSet(vlc_object_instance(intf), &log_ops, sys);
1680 sys->box_type = BOX_PLAYLIST;
1681 sys->plidx_follow = true;
1682 sys->color = var_CreateGetBool(intf, "color");
1684 sys->current_dir = var_CreateGetNonEmptyString(intf, "browse-dir");
1685 if (!sys->current_dir)
1686 sys->current_dir = config_GetUserDir(VLC_HOME_DIR);
1688 initscr(); /* Initialize the curses library */
1691 start_color_and_pairs(intf);
1693 keypad(stdscr, TRUE);
1694 nonl(); /* Don't do NL -> CR/NL */
1695 cbreak(); /* Take input chars one at a time */
1696 noecho(); /* Don't echo */
1697 curs_set(0); /* Invisible cursor */
1698 timeout(1000); /* blocking getch() */
1701 /* Stop printing errors to the console */
1702 if (!freopen("/dev/null", "wb", stderr))
1703 msg_Err(intf, "Couldn't close stderr (%s)", vlc_strerror_c(errno));
1707 int err = VLC_EGENERIC;
1708 sys->playlist = vlc_intf_GetMainPlaylist(intf);
1710 static struct vlc_playlist_callbacks const playlist_cbs =
1712 .on_items_added = playlist_on_items_added,
1713 .on_items_updated = playlist_on_items_updated,
1715 vlc_playlist_Lock(sys->playlist);
1716 PlaylistRebuild(intf);
1717 sys->playlist_listener =
1718 vlc_playlist_AddListener(sys->playlist, &playlist_cbs, sys, false);
1719 vlc_playlist_Unlock(sys->playlist);
1720 if (!sys->playlist_listener)
1723 if (vlc_clone(&sys->thread, Run, intf, VLC_THREAD_PRIORITY_LOW))
1725 vlc_playlist_Lock(sys->playlist);
1726 vlc_playlist_RemoveListener(sys->playlist, sys->playlist_listener);
1727 vlc_playlist_Unlock(sys->playlist);
1734 /*****************************************************************************
1735 * Close: destroy interface window
1736 *****************************************************************************/
1737 static void Close(vlc_object_t *p_this)
1739 intf_thread_t *intf = (intf_thread_t *)p_this;
1740 intf_sys_t *sys = intf->p_sys;
1742 atomic_store_explicit(&sys->alive, false, memory_order_relaxed);
1743 vlc_join(sys->thread, NULL);
1745 vlc_playlist_t *playlist = sys->playlist;
1746 vlc_playlist_Lock(playlist);
1747 vlc_playlist_RemoveListener(playlist, sys->playlist_listener);
1748 vlc_playlist_Unlock(playlist);
1750 for (size_t i = 0; i < sys->pl_item_names.size; ++i)
1751 free((void *)sys->pl_item_names.data[i]);
1752 vlc_vector_clear(&sys->pl_item_names);
1756 free(sys->current_dir);
1758 if (can_change_color())
1759 /* Restore yellow to its original color */
1760 init_color(COLOR_YELLOW, sys->yellow_r, sys->yellow_g, sys->yellow_b);
1762 endwin(); /* Close the ncurses interface */
1764 vlc_LogSet(vlc_object_instance(p_this), NULL, NULL);
1765 for(unsigned i = 0; i < sizeof sys->msgs / sizeof *sys->msgs; i++) {
1766 if (sys->msgs[i].item)
1767 msg_Free(sys->msgs[i].item);
1768 free(sys->msgs[i].msg);