Commit 6f54dbe4 authored by Cheng Sun's avatar Cheng Sun

GTK: when dragging volume and time sliders, do not bombard libvlc with too...

GTK: when dragging volume and time sliders, do not bombard libvlc with too many requests by implementing a timer delay.
parent ceda3221
......@@ -37,9 +37,13 @@ VlcPluginGtk::VlcPluginGtk(NPP instance, NPuint16_t mode) :
parent_vbox(NULL),
video_container(NULL),
toolbar(NULL),
time_slider(NULL),
vol_slider(NULL),
fullscreen_win(NULL),
is_fullscreen(false),
is_toolbar_visible(false)
is_toolbar_visible(false),
time_slider_timeout_id(0),
vol_slider_timeout_id(0)
{
memset(&video_xwindow, 0, sizeof(Window));
GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
......@@ -292,21 +296,53 @@ static bool video_expose_handler(GtkWidget *widget, GdkEvent *event, gpointer us
return true;
}
static bool time_slider_handler(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data)
static gboolean do_time_slider_handler(gpointer user_data)
{
VlcPluginGtk *plugin = (VlcPluginGtk *) user_data;
libvlc_media_player_t *md = plugin->getMD();
if (md)
if (md) {
gdouble value = gtk_range_get_value(GTK_RANGE(plugin->time_slider));
libvlc_media_player_set_position(md, value/100.0);
}
plugin->time_slider_timeout_id = 0;
return FALSE;
}
static bool time_slider_handler(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data)
{
VlcPluginGtk *plugin = (VlcPluginGtk *) user_data;
if (plugin->time_slider_timeout_id != 0)
return false;
plugin->time_slider_timeout_id = g_timeout_add(500,
do_time_slider_handler,
user_data);
return false;
}
static bool vol_slider_handler(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data)
static gboolean do_vol_slider_handler(gpointer user_data)
{
VlcPluginGtk *plugin = (VlcPluginGtk *) user_data;
libvlc_media_player_t *md = plugin->getMD();
if (md)
if (md) {
gdouble value = gtk_range_get_value(GTK_RANGE(plugin->vol_slider));
libvlc_audio_set_volume(md, value);
}
plugin->vol_slider_timeout_id = 0;
return FALSE;
}
static bool vol_slider_handler(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data)
{
VlcPluginGtk *plugin = (VlcPluginGtk *) user_data;
if (plugin->vol_slider_timeout_id != 0)
return false;
plugin->vol_slider_timeout_id = g_timeout_add(100,
do_vol_slider_handler,
user_data);
return false;
}
......@@ -356,8 +392,11 @@ void VlcPluginGtk::update_controls()
} else {
gtk_widget_set_sensitive(time_slider, true);
gdouble timepos = 100*libvlc_media_player_get_position(libvlc_media_player);
if (time_slider_timeout_id == 0) {
/* only set the time if the user is not dragging the slider */
gtk_range_set_value(GTK_RANGE(time_slider), timepos);
}
}
gtk_widget_show_all(toolbar);
}
......@@ -448,7 +487,7 @@ bool VlcPluginGtk::create_windows()
/* volume slider */
toolitem = gtk_tool_item_new();
GtkWidget *vol_slider = gtk_hscale_new_with_range(0, 200, 10);
vol_slider = gtk_hscale_new_with_range(0, 200, 10);
gtk_scale_set_draw_value(GTK_SCALE(vol_slider), false);
g_signal_connect(G_OBJECT(vol_slider), "change-value", G_CALLBACK(vol_slider_handler), this);
gtk_range_set_value(GTK_RANGE(vol_slider), 100);
......
......@@ -54,14 +54,16 @@ public:
void resize_video_xwindow(GdkRectangle *rect);
GdkPixbuf *cone_icon;
GtkWidget *time_slider, *vol_slider;
guint time_slider_timeout_id, vol_slider_timeout_id;
private:
void set_player_window();
Display *get_display() { return display; }
unsigned int i_width, i_height;
GtkWidget *parent, *parent_vbox, *video_container;
GtkWidget *toolbar, *time_slider;
GtkWidget *fullscreen_win;
GtkWidget *toolbar;
gulong video_container_size_handler_id;
Display *display;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment