[vlc-commits] commit: ncurses: fix #1987 ( Rafaël Carré )
git at videolan.org
git at videolan.org
Sun Oct 31 15:06:25 CET 2010
vlc | branch: master | Rafaël Carré <rafael.carre at gmail.com> | Sun Oct 31 15:02:32 2010 +0100| [ea7a0fecb1d618cad7542cff72a0663c76c46f92] | committer: Rafaël Carré
ncurses: fix #1987
Use a ncurses timeout() of 1 second, which will block when waiting for input
We use 1 second so the position slider is refreshed correctly
We could use 500ms to not miss any change, now the slider can make a
2 seconds jump, see Nyquist-Shannon theorem
Add a variable to the context to exit the main loop as soon as the exit key
is pressed, so we don't have to wait one more second: vlc_object_alive()
doesn't return false immediately after calling libvlc_Quit()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ea7a0fecb1d618cad7542cff72a0663c76c46f92
---
modules/gui/ncurses.c | 24 +++++++++---------------
1 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/modules/gui/ncurses.c b/modules/gui/ncurses.c
index 43f57a0..6cb13f7 100644
--- a/modules/gui/ncurses.c
+++ b/modules/gui/ncurses.c
@@ -181,6 +181,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
@@ -1200,7 +1201,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;
@@ -1225,7 +1226,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)
@@ -1606,6 +1606,7 @@ static bool HandleCommonKey(intf_thread_t *p_intf, int key)
case 'Q':
case KEY_EXIT:
libvlc_Quit(p_intf->p_libvlc);
+ p_sys->b_exit = true; // terminate the main loop
return false;
case 'h':
@@ -1774,23 +1775,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);
+ Redraw(p_intf);
}
else if (p_sys->p_input->b_dead)
{
@@ -1798,11 +1794,9 @@ static void Run(intf_thread_t *p_intf)
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);
+ do
+ Redraw(p_intf);
+ while (HandleKey(p_intf));
}
var_DelCallback(p_playlist, "intf-change", PlaylistChanged, p_intf);
var_DelCallback(p_playlist, "playlist-item-append", PlaylistChanged, p_intf);
@@ -1857,7 +1851,7 @@ static int Open(vlc_object_t *p_this)
cbreak(); /* Don't echo */
noecho(); /* Invisible cursor */
curs_set(0); /* Non blocking wgetch() */
- timeout(0);
+ timeout(1000);
clear();
/* Stop printing errors to the console */
More information about the vlc-commits
mailing list