summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-02-12 21:59:40 +0100
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-02-12 21:59:40 +0100
commitb7e6b93e538f666e9bc036db11ebd5293a563051 (patch)
tree715a999d0d1feccf78d300feb55839c710ef633b
parent2135fdf53fcaca8a9fd079960db85ea987d8bfbf (diff)
gtkui: ported volumebar to widget system
-rw-r--r--plugins/gtkui/ddbseekbar.c2
-rw-r--r--plugins/gtkui/ddbvolumebar.c48
-rw-r--r--plugins/gtkui/ddbvolumebar.h3
-rw-r--r--plugins/gtkui/gtkui.c34
-rw-r--r--plugins/gtkui/gtkui.h3
-rw-r--r--plugins/gtkui/prefwin.c1
-rw-r--r--plugins/gtkui/widgets.c45
-rw-r--r--plugins/gtkui/widgets.h3
8 files changed, 101 insertions, 38 deletions
diff --git a/plugins/gtkui/ddbseekbar.c b/plugins/gtkui/ddbseekbar.c
index 104ad811..71243c80 100644
--- a/plugins/gtkui/ddbseekbar.c
+++ b/plugins/gtkui/ddbseekbar.c
@@ -459,7 +459,7 @@ on_evbox_button_press_event (GtkWidget *widget,
return gtk_widget_event (GTK_WIDGET (user_data), (GdkEvent *)event);
}
-gboolean
+static gboolean
on_evbox_button_release_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
diff --git a/plugins/gtkui/ddbvolumebar.c b/plugins/gtkui/ddbvolumebar.c
index e56ca03c..38d93c45 100644
--- a/plugins/gtkui/ddbvolumebar.c
+++ b/plugins/gtkui/ddbvolumebar.c
@@ -311,3 +311,51 @@ on_volumebar_configure_event (GtkWidget *widget, GdkEventConfigure *event) {
gtkui_init_theme_colors ();
return FALSE;
}
+
+static gboolean
+on_evbox_button_press_event (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
+{
+ return gtk_widget_event (GTK_WIDGET (user_data), (GdkEvent *)event);
+}
+
+static 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_volumebar_init_signals (DdbVolumeBar *vb, GtkWidget *evbox) {
+ g_signal_connect ((gpointer) evbox, "button_press_event",
+ G_CALLBACK (on_evbox_button_press_event),
+ vb);
+ g_signal_connect ((gpointer) evbox, "button_release_event",
+ G_CALLBACK (on_evbox_button_release_event),
+ vb);
+ g_signal_connect ((gpointer) evbox, "scroll_event",
+ G_CALLBACK (on_evbox_scroll_event),
+ vb);
+ g_signal_connect ((gpointer) evbox, "motion_notify_event",
+ G_CALLBACK (on_evbox_motion_notify_event),
+ vb);
+}
+
diff --git a/plugins/gtkui/ddbvolumebar.h b/plugins/gtkui/ddbvolumebar.h
index e8ef0a2d..d560a5cd 100644
--- a/plugins/gtkui/ddbvolumebar.h
+++ b/plugins/gtkui/ddbvolumebar.h
@@ -48,6 +48,9 @@ struct _DdbVolumeBarClass {
GType ddb_volumebar_get_type(void) G_GNUC_CONST;
GtkWidget * ddb_volumebar_new(void);
+void
+ddb_volumebar_init_signals (DdbVolumeBar *vb, GtkWidget *evbox);
+
G_END_DECLS
#endif // __DDBVOLUMEBAR_H
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index 0aaab36c..061b0184 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -272,17 +272,6 @@ on_trayicon_scroll_event (GtkWidget *widget,
vol = deadbeef->volume_get_min_db ();
}
deadbeef->volume_set_db (vol);
- volumebar_redraw ();
-
- //Update volume bar tooltip
- if (mainwin) {
- GtkWidget *volumebar = lookup_widget (mainwin, "volumebar");
- char s[100];
- int db = vol;
- snprintf (s, sizeof (s), "%s%ddB", db < 0 ? "" : "+", db);
- gtk_widget_set_tooltip_text (volumebar, s);
- gtk_widget_trigger_tooltip_query (volumebar);
- }
#if 0
char str[100];
@@ -490,13 +479,6 @@ gtkui_on_frameupdate (gpointer data) {
}
static gboolean
-gtkui_volumechanged_cb (gpointer ctx) {
- GtkWidget *volumebar = lookup_widget (mainwin, "volumebar");
- gdk_window_invalidate_rect (gtk_widget_get_window (volumebar), NULL, FALSE);
- return FALSE;
-}
-
-static gboolean
gtkui_update_status_icon (gpointer unused) {
int hide_tray_icon = deadbeef->conf_get_int ("gtkui.hide_tray_icon", 0);
if (hide_tray_icon && !trayicon) {
@@ -704,18 +686,6 @@ gtkui_add_new_playlist (void) {
return -1;
}
-void
-volumebar_redraw (void) {
- GtkWidget *volumebar = lookup_widget (mainwin, "volumebar");
- gdk_window_invalidate_rect (gtk_widget_get_window (volumebar), NULL, FALSE);
-}
-
-//void
-//tabstrip_redraw (void) {
-// GtkWidget *ts = lookup_widget (mainwin, "tabstrip");
-// ddb_tabstrip_refresh (DDB_TABSTRIP (ts));
-//}
-
static gint refresh_timeout = 0;
int
@@ -810,9 +780,6 @@ gtkui_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
case DB_EV_PLAYLISTCHANGED:
g_idle_add (playlistchanged_cb, NULL);
break;
- case DB_EV_VOLUMECHANGED:
- g_idle_add (gtkui_volumechanged_cb, NULL);
- break;
case DB_EV_CONFIGCHANGED:
g_idle_add (gtkui_on_configchanged, NULL);
break;
@@ -965,6 +932,7 @@ gtkui_thread (void *ctx) {
w_reg_widget (_("Button"), 0, w_button_create, "button", NULL);
w_reg_widget (_("Seekbar"), 0, w_seekbar_create, "seekbar", NULL);
w_reg_widget (_("Playback controls"), 0, w_playtb_create, "playtb", NULL);
+ w_reg_widget (_("Volume bar"), 0, w_volumebar_create, "volumebar", NULL);
mainwin = create_mainwin ();
diff --git a/plugins/gtkui/gtkui.h b/plugins/gtkui/gtkui.h
index 803beccb..da0882b2 100644
--- a/plugins/gtkui/gtkui.h
+++ b/plugins/gtkui/gtkui.h
@@ -109,9 +109,6 @@ on_seekbar_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event);
void
-volumebar_redraw (void);
-
-void
gtkui_set_titlebar (DB_playItem_t *it);
gboolean
diff --git a/plugins/gtkui/prefwin.c b/plugins/gtkui/prefwin.c
index b90f8283..40f9b475 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 ();
- volumebar_redraw ();
eq_redraw ();
}
diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
index af8affa2..ea41174b 100644
--- a/plugins/gtkui/widgets.c
+++ b/plugins/gtkui/widgets.c
@@ -40,6 +40,7 @@
#include "../../fastftoi.h"
#include "actions.h"
#include "ddbseekbar.h"
+#include "ddbvolumebar.h"
#include "callbacks.h"
//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
@@ -206,6 +207,11 @@ typedef struct {
ddb_gtkui_widget_t base;
} w_playtb_t;
+typedef struct {
+ ddb_gtkui_widget_t base;
+ GtkWidget *volumebar;
+} w_volumebar_t;
+
static int design_mode;
static ddb_gtkui_widget_t *rootwidget;
@@ -3629,3 +3635,42 @@ w_playtb_create (void) {
NULL);
return (ddb_gtkui_widget_t*)w;
}
+
+// volumebar
+static gboolean
+redraw_volumebar_cb (gpointer data) {
+ w_volumebar_t *w = data;
+ gtk_widget_queue_draw (w->volumebar);
+ char s[100];
+ int db = deadbeef->volume_get_db ();
+ snprintf (s, sizeof (s), "%s%ddB", db < 0 ? "" : "+", db);
+ gtk_widget_set_tooltip_text (w->volumebar, s);
+ gtk_widget_trigger_tooltip_query (w->volumebar);
+ return FALSE;
+}
+
+static int
+w_volumebar_message (ddb_gtkui_widget_t *w, uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
+ switch (id) {
+ case DB_EV_CONFIGCHANGED:
+ case DB_EV_VOLUMECHANGED:
+ g_idle_add (redraw_volumebar_cb, w);
+ break;
+ }
+ return 0;
+}
+
+ddb_gtkui_widget_t *
+w_volumebar_create (void) {
+ w_volumebar_t *w = malloc (sizeof (w_volumebar_t));
+ memset (w, 0, sizeof (w_volumebar_t));
+ w->base.widget = gtk_event_box_new ();
+ w->base.message = w_volumebar_message;
+ w->volumebar = ddb_volumebar_new ();
+ ddb_volumebar_init_signals (DDB_VOLUMEBAR (w->volumebar), w->base.widget);
+ gtk_widget_show (w->volumebar);
+ gtk_widget_set_size_request (w->volumebar, 70, -1);
+ gtk_container_add (GTK_CONTAINER (w->base.widget), w->volumebar);
+ w_override_signals (w->base.widget, w);
+ return (ddb_gtkui_widget_t*)w;
+}
diff --git a/plugins/gtkui/widgets.h b/plugins/gtkui/widgets.h
index 295db5d9..e9392325 100644
--- a/plugins/gtkui/widgets.h
+++ b/plugins/gtkui/widgets.h
@@ -128,4 +128,7 @@ w_seekbar_create (void);
ddb_gtkui_widget_t *
w_playtb_create (void);
+ddb_gtkui_widget_t *
+w_volumebar_create (void);
+
#endif