diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2014-02-12 21:28:30 +0100 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2014-02-12 21:28:30 +0100 |
commit | 4db09a9c8c98d9c3f0ac975fcb4789b954a52325 (patch) | |
tree | db0cfef469814a3e5be94133c085c21638239776 /plugins/gtkui | |
parent | 039fe06416e982577e7631ddcf8539e29e2e1c5e (diff) |
gtkui: ported seekbar to widget system
Diffstat (limited to 'plugins/gtkui')
-rw-r--r-- | plugins/gtkui/ddbseekbar.c | 53 | ||||
-rw-r--r-- | plugins/gtkui/ddbseekbar.h | 10 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 29 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.h | 6 | ||||
-rw-r--r-- | plugins/gtkui/prefwin.c | 1 | ||||
-rw-r--r-- | plugins/gtkui/widgets.c | 89 | ||||
-rw-r--r-- | plugins/gtkui/widgets.h | 3 |
7 files changed, 159 insertions, 32 deletions
diff --git a/plugins/gtkui/ddbseekbar.c b/plugins/gtkui/ddbseekbar.c index 31740a29..104ad811 100644 --- a/plugins/gtkui/ddbseekbar.c +++ b/plugins/gtkui/ddbseekbar.c @@ -52,7 +52,6 @@ static gboolean ddb_seekbar_real_button_press_event (GtkWidget* base, GdkEventBu static gboolean ddb_seekbar_real_button_release_event (GtkWidget* base, GdkEventButton* event); static gboolean ddb_seekbar_real_motion_notify_event (GtkWidget* base, GdkEventMotion* event); static gboolean ddb_seekbar_real_configure_event (GtkWidget* base, GdkEventConfigure* event); -DdbSeekbar* ddb_seekbar_new (void); DdbSeekbar* ddb_seekbar_construct (GType object_type); static GObject * ddb_seekbar_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties); @@ -158,8 +157,8 @@ DdbSeekbar* ddb_seekbar_construct (GType object_type) { } -DdbSeekbar* ddb_seekbar_new (void) { - return ddb_seekbar_construct (DDB_TYPE_SEEKBAR); +GtkWidget* ddb_seekbar_new (void) { + return GTK_WIDGET (ddb_seekbar_construct (DDB_TYPE_SEEKBAR)); } @@ -452,10 +451,50 @@ on_seekbar_button_release_event (GtkWidget *widget, return FALSE; } -void -seekbar_redraw (void) { - GtkWidget *widget = lookup_widget (mainwin, "seekbar"); - gtk_widget_queue_draw (widget); +static gboolean +on_evbox_button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) +{ + return gtk_widget_event (GTK_WIDGET (user_data), (GdkEvent *)event); +} + +gboolean +on_evbox_button_release_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) +{ + return gtk_widget_event (GTK_WIDGET (user_data), (GdkEvent *)event); } +static gboolean +on_evbox_motion_notify_event (GtkWidget *widget, + GdkEventMotion *event, + gpointer user_data) +{ + return gtk_widget_event (GTK_WIDGET (user_data), (GdkEvent *)event); +} + +static gboolean +on_evbox_scroll_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) { + return gtk_widget_event (GTK_WIDGET (user_data), (GdkEvent *)event); +} + +void +ddb_seekbar_init_signals (DdbSeekbar *sb, GtkWidget *evbox) { + g_signal_connect ((gpointer) evbox, "button_press_event", + G_CALLBACK (on_evbox_button_press_event), + sb); + g_signal_connect ((gpointer) evbox, "button_release_event", + G_CALLBACK (on_evbox_button_release_event), + sb); + g_signal_connect ((gpointer) evbox, "scroll_event", + G_CALLBACK (on_evbox_scroll_event), + sb); + g_signal_connect ((gpointer) evbox, "motion_notify_event", + G_CALLBACK (on_evbox_motion_notify_event), + sb); +} diff --git a/plugins/gtkui/ddbseekbar.h b/plugins/gtkui/ddbseekbar.h index 7ce90052..b4e470bc 100644 --- a/plugins/gtkui/ddbseekbar.h +++ b/plugins/gtkui/ddbseekbar.h @@ -34,10 +34,14 @@ struct _DdbSeekbarClass { }; -GType ddb_seekbar_get_type (void); -DdbSeekbar* ddb_seekbar_new (void); -DdbSeekbar* ddb_seekbar_construct (GType object_type); +GType +ddb_seekbar_get_type (void); +GtkWidget* +ddb_seekbar_new (void); + +void +ddb_seekbar_init_signals (DdbSeekbar *sb, GtkWidget *evbox); G_END_DECLS diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index bb89b17d..3e245901 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -149,7 +149,6 @@ update_songinfo (gpointer ctx) { } DB_output_t *output = deadbeef->get_output (); char sbtext_new[512] = "-"; - float songpos = last_songpos; float pl_totaltime = deadbeef->pl_get_totaltime (); int daystotal = (int)pl_totaltime / (3600*24); @@ -175,7 +174,6 @@ update_songinfo (gpointer ctx) { if (!output || (output->state () == OUTPUT_STATE_STOPPED || !track || !c)) { snprintf (sbtext_new, sizeof (sbtext_new), _("Stopped | %d tracks | %s total playtime"), deadbeef->pl_getcount (PL_MAIN), totaltime_str); - songpos = 0; } else { float playpos = deadbeef->streamer_get_playpos (); @@ -195,7 +193,6 @@ update_songinfo (gpointer ctx) { } int samplerate = c->fmt.samplerate; int bitspersample = c->fmt.bps; - songpos = playpos; // codec_unlock (); char t[100]; @@ -240,18 +237,6 @@ update_songinfo (gpointer ctx) { gtk_statusbar_push (sb, sb_context_id, sb_text); } - if (mainwin) { - GtkWidget *widget = lookup_widget (mainwin, "seekbar"); - // translate volume to seekbar pixels - songpos /= duration; - GtkAllocation a; - gtk_widget_get_allocation (widget, &a); - songpos *= a.width; - if (fabs (songpos - last_songpos) > 0.01) { - gtk_widget_queue_draw (widget); - last_songpos = songpos; - } - } if (track) { deadbeef->pl_item_unref (track); } @@ -692,12 +677,15 @@ update_win_title_idle (gpointer data) { static gboolean redraw_seekbar_cb (gpointer nothing) { + return FALSE; +#if 0 int iconified = gdk_window_get_state(gtk_widget_get_window(mainwin)) & GDK_WINDOW_STATE_ICONIFIED; if (!gtk_widget_get_visible (mainwin) || iconified) { return FALSE; } seekbar_redraw (); return FALSE; +#endif } int @@ -746,8 +734,8 @@ volumebar_redraw (void) { static gint refresh_timeout = 0; -void -gtkui_setup_gui_refresh (void) { +int +gtkui_get_gui_refresh_rate () { int fps = deadbeef->conf_get_int ("gtkui.refresh_rate", 10); if (fps < 1) { fps = 1; @@ -755,8 +743,12 @@ gtkui_setup_gui_refresh (void) { else if (fps > 30) { fps = 30; } + return fps; +} - int tm = 1000/fps; +void +gtkui_setup_gui_refresh (void) { + int tm = 1000/gtkui_get_gui_refresh_rate (); if (refresh_timeout) { g_source_remove (refresh_timeout); @@ -987,6 +979,7 @@ gtkui_thread (void *ctx) { w_reg_widget (_("HBox"), 0, w_hbox_create, "hbox", NULL); w_reg_widget (_("VBox"), 0, w_vbox_create, "vbox", NULL); w_reg_widget (_("Button"), 0, w_button_create, "button", NULL); + w_reg_widget (_("Seekbar"), 0, w_seekbar_create, "seekbar", NULL); mainwin = create_mainwin (); diff --git a/plugins/gtkui/gtkui.h b/plugins/gtkui/gtkui.h index abd71af7..803beccb 100644 --- a/plugins/gtkui/gtkui.h +++ b/plugins/gtkui/gtkui.h @@ -94,9 +94,6 @@ int gtkui_add_new_playlist (void); void -seekbar_redraw (void); - -void seekbar_draw (GtkWidget *widget, cairo_t *cr); gboolean @@ -162,4 +159,7 @@ gtkui_quit (void); void gtkui_run_preferences_dlg (void); +int +gtkui_get_gui_refresh_rate (); + #endif diff --git a/plugins/gtkui/prefwin.c b/plugins/gtkui/prefwin.c index 6034feef..b90f8283 100644 --- a/plugins/gtkui/prefwin.c +++ b/plugins/gtkui/prefwin.c @@ -773,7 +773,6 @@ on_override_bar_colors_toggled (GtkToggleButton *togglebutton, deadbeef->sendmessage (DB_EV_CONFIGCHANGED, 0, 0, 0); gtkui_init_theme_colors (); prefwin_init_theme_colors (); - seekbar_redraw (); volumebar_redraw (); eq_redraw (); } diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c index c505d776..7d753b30 100644 --- a/plugins/gtkui/widgets.c +++ b/plugins/gtkui/widgets.c @@ -39,6 +39,7 @@ #include "../../strdupa.h" #include "../../fastftoi.h" #include "actions.h" +#include "ddbseekbar.h" //#define trace(...) { fprintf(stderr, __VA_ARGS__); } #define trace(fmt,...) @@ -193,6 +194,13 @@ typedef struct { unsigned use_textcolor : 1; } w_button_t; +typedef struct { + ddb_gtkui_widget_t base; + GtkWidget *seekbar; + gint timer; + float last_songpos; +} w_seekbar_t; + static int design_mode; static ddb_gtkui_widget_t *rootwidget; @@ -3445,3 +3453,84 @@ w_button_create (void) { w_override_signals (w->base.widget, w); return (ddb_gtkui_widget_t *)w; } + +// seekbar +static gboolean +redraw_seekbar_cb (gpointer data) { + w_seekbar_t *w = data; + int iconified = gdk_window_get_state(gtk_widget_get_window(mainwin)) & GDK_WINDOW_STATE_ICONIFIED; + if (!gtk_widget_get_visible (mainwin) || iconified) { + return FALSE; + } + gtk_widget_queue_draw (w->seekbar); + return FALSE; +} + +static int +w_seekbar_message (ddb_gtkui_widget_t *w, uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_SONGCHANGED: + case DB_EV_CONFIGCHANGED: + { + ddb_event_trackchange_t *ev = (ddb_event_trackchange_t *)ctx; + g_idle_add (redraw_seekbar_cb, w); + } + break; + } + return 0; +} + +static gboolean +seekbar_frameupdate (gpointer data) { + w_seekbar_t *w = data; + DB_output_t *output = deadbeef->get_output (); + DB_playItem_t *track = deadbeef->streamer_get_playing_track (); + DB_fileinfo_t *c = deadbeef->streamer_get_current_fileinfo (); // FIXME: might crash streamer + float songpos = w->last_songpos; + float duration = track ? deadbeef->pl_get_item_duration (track) : -1; + if (!output || (output->state () == OUTPUT_STATE_STOPPED || !track || !c)) { + songpos = 0; + } + else { + songpos = deadbeef->streamer_get_playpos (); + } + // translate pos to seekbar pixels + songpos /= duration; + GtkAllocation a; + gtk_widget_get_allocation (w->seekbar, &a); + songpos *= a.width; + if (fabs (songpos - w->last_songpos) > 0.01) { + gtk_widget_queue_draw (w->seekbar); + w->last_songpos = songpos; + } + if (track) { + deadbeef->pl_item_unref (track); + } + return TRUE; +} + +static void +w_seekbar_destroy (ddb_gtkui_widget_t *wbase) { + w_seekbar_t *w = (w_seekbar_t *)wbase; + if (w->timer) { + g_source_remove (w->timer); + w->timer = 0; + } +} + +ddb_gtkui_widget_t * +w_seekbar_create (void) { + w_seekbar_t *w = malloc (sizeof (w_seekbar_t)); + memset (w, 0, sizeof (w_seekbar_t)); + w->base.widget = gtk_event_box_new (); + w->base.message = w_seekbar_message; + w->base.destroy = w_seekbar_destroy; + w->seekbar = ddb_seekbar_new (); + w->last_songpos = -1; + ddb_seekbar_init_signals (DDB_SEEKBAR (w->seekbar), w->base.widget); + gtk_widget_show (w->seekbar); + gtk_container_add (GTK_CONTAINER (w->base.widget), w->seekbar); + w_override_signals (w->base.widget, w); + w->timer = g_timeout_add (1000/gtkui_get_gui_refresh_rate (), seekbar_frameupdate, w); + return (ddb_gtkui_widget_t*)w; +} diff --git a/plugins/gtkui/widgets.h b/plugins/gtkui/widgets.h index 964fb665..5a517e55 100644 --- a/plugins/gtkui/widgets.h +++ b/plugins/gtkui/widgets.h @@ -122,4 +122,7 @@ w_vbox_create (void); ddb_gtkui_widget_t * w_button_create (void); +ddb_gtkui_widget_t * +w_seekbar_create (void); + #endif |