Commit 86e16b68 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

npapi: gtk: Update position slider

Simplify both slider handling
parent 3827e612
......@@ -43,8 +43,7 @@ VlcPluginGtk::VlcPluginGtk(NPP instance, NPuint16_t mode) :
fullscreen_win(NULL),
is_fullscreen(false),
is_toolbar_visible(false),
time_slider_timeout_id(0),
vol_slider_timeout_id(0)
m_timer_update_timeout( 0 )
{
memset(&video_xwindow, 0, sizeof(Window));
GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
......@@ -55,6 +54,15 @@ VlcPluginGtk::VlcPluginGtk(NPP instance, NPuint16_t mode) :
}
}
VlcPluginGtk::~VlcPluginGtk()
{
{
std::lock_guard<std::mutex> lock( m_timer_lock );
if ( m_timer_update_timeout != 0 )
g_source_remove( m_timer_update_timeout );
}
}
void VlcPluginGtk::set_player_window()
{
player().get_mp().setXwindow( video_xwindow);
......@@ -298,53 +306,29 @@ static bool video_expose_handler(GtkWidget *widget, GdkEvent *event, gpointer us
return true;
}
static gboolean do_time_slider_handler(gpointer user_data)
gboolean VlcPluginGtk::update_time_slider(gpointer user_data)
{
VlcPluginGtk *plugin = (VlcPluginGtk *) user_data;
auto md = plugin->getMD();
if (md) {
gdouble value = gtk_range_get_value(GTK_RANGE(plugin->time_slider));
md.setPosition( value / 100.0 );
}
plugin->time_slider_timeout_id = 0;
std::lock_guard<std::mutex> lock( plugin->m_timer_lock );
auto pos = plugin->player().get_mp().position() * 100.0f;
gtk_range_set_value( GTK_RANGE( plugin->time_slider ), pos );
plugin->m_timer_update_timeout = 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);
plugin->getMD().setPosition( value / 100.0 );
return false;
}
static gboolean do_vol_slider_handler(gpointer user_data)
{
VlcPluginGtk *plugin = (VlcPluginGtk *) user_data;
auto md = plugin->getMD();
if (md) {
gdouble value = gtk_range_get_value(GTK_RANGE(plugin->vol_slider));
md.setVolume( 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);
plugin->getMD().setVolume( value );
return false;
}
......@@ -403,11 +387,6 @@ void VlcPluginGtk::update_controls()
gtk_range_set_value(GTK_RANGE(time_slider), 0);
} else {
gtk_widget_set_sensitive(time_slider, true);
gdouble timepos = 100.0 * player().get_mp().position();
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);
......@@ -498,6 +477,11 @@ bool VlcPluginGtk::create_windows()
gtk_container_add(GTK_CONTAINER(toolitem), time_slider);
gtk_tool_item_set_expand(toolitem, true);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
m_player.get_mp().eventManager().onPositionChanged([this](float) {
std::lock_guard<std::mutex> lock( m_timer_lock );
if ( m_timer_update_timeout == 0 )
m_timer_update_timeout = g_timeout_add( 100, update_time_slider, (gpointer)this);
});
/* volume slider */
toolitem = gtk_tool_item_new();
......
......@@ -27,6 +27,7 @@
#include "vlcplugin_base.h"
#include <gtk/gtk.h>
#include <mutex>
#include <X11/Xlib.h>
#define VLCPLUGINGTK_MENU_TOOLBAR "Show toolbar"
......@@ -35,6 +36,7 @@ class VlcPluginGtk : public VlcPluginBase
{
public:
VlcPluginGtk(NPP, NPuint16_t);
virtual ~VlcPluginGtk();
bool create_windows();
bool resize_windows();
......@@ -54,10 +56,11 @@ public:
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; }
static gboolean update_time_slider(gpointer user_data);
unsigned int i_width, i_height;
GtkWidget *parent, *parent_vbox, *video_container;
......@@ -69,6 +72,8 @@ private:
Window video_xwindow;
XColor bg_color;
bool is_fullscreen, is_toolbar_visible;
std::mutex m_timer_lock;
guint m_timer_update_timeout;
};
#endif /* __VLCPLUGIN_GTK_H__ */
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