aboutsummaryrefslogtreecommitdiff
path: root/src/transport-widget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport-widget.c')
-rw-r--r--src/transport-widget.c216
1 files changed, 99 insertions, 117 deletions
diff --git a/src/transport-widget.c b/src/transport-widget.c
index f05c4c1..564b76f 100644
--- a/src/transport-widget.c
+++ b/src/transport-widget.c
@@ -31,7 +31,7 @@ Uses code from ctk
#define RECT_WIDTH 130.0f
#define Y 7.0f
-#define X 80.0f
+#define X 70.0f
#define INNER_RADIUS 12.5
#define MIDDLE_RADIUS 13.0f
#define OUTER_RADIUS 14.5f
@@ -43,16 +43,16 @@ Uses code from ctk
#define TRI_WIDTH 11.0f
#define TRI_HEIGHT 13.0f
#define TRI_OFFSET 6.0f
-#define PREV_X 78.0f
+#define PREV_X 68.0f
#define PREV_Y 13.0f
-#define NEXT_X 156.0f
+#define NEXT_X 146.0f
#define NEXT_Y 13.0f //prev_y
#define PAUSE_WIDTH 21.0f
#define PAUSE_HEIGHT 27.0f
#define BAR_WIDTH 4.5f
#define BAR_HEIGHT 24.0f
#define BAR_OFFSET 10.0f
-#define PAUSE_X 121.0f
+#define PAUSE_X 111.0f
#define PAUSE_Y 7.0f
#define PLAY_WIDTH 28.0f
#define PLAY_HEIGHT 29.0f
@@ -85,11 +85,14 @@ struct _TransportWidgetPrivate
gboolean has_focus;
gint hold_timer;
gint skip_frequency;
- gint launching_timer;
- gdouble launching_transparency;
- gboolean fade_out;
};
+#if GTK_CHECK_VERSION(3, 0, 0)
+static GList *transport_widget_list = NULL;
+static GtkStyleContext *spinner_style_context = NULL;
+static GtkWidgetPath *spinner_widget_path = NULL;
+#endif
+
// TODO refactor the UI handlers, consolidate functionality between key press /release
// and button press / release.
#define TRANSPORT_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRANSPORT_WIDGET_TYPE, TransportWidgetPrivate))
@@ -104,8 +107,10 @@ G_DEFINE_TYPE (TransportWidget, transport_widget, GTK_TYPE_MENU_ITEM);
/* essentials */
static void transport_widget_set_twin_item ( TransportWidget* self,
DbusmenuMenuitem* twin_item);
+#if ! GTK_CHECK_VERSION(3, 0, 0)
static gboolean transport_widget_expose ( GtkWidget *button, GdkEventExpose *event);
-static void draw (GtkWidget* button, cairo_t *cr);
+#endif
+static gboolean draw (GtkWidget* button, cairo_t *cr);
/* UI and dbusmenu callbacks */
static gboolean transport_widget_button_press_event (GtkWidget *menuitem,
@@ -133,13 +138,12 @@ static void transport_widget_react_to_button_release ( TransportWidget* button,
TransportAction command);
static void transport_widget_toggle_play_pause ( TransportWidget* button,
TransportState update);
-static void transport_widget_select (GtkItem* menu, gpointer Userdata);
-static void transport_widget_deselect (GtkItem* menu, gpointer Userdata);
+static void transport_widget_select (GtkWidget* menu, gpointer Userdata);
+static void transport_widget_deselect (GtkWidget* menu, gpointer Userdata);
static TransportAction transport_widget_collision_detection (gint x, gint y);
static void transport_widget_start_timing (TransportWidget* widget);
static gboolean transport_widget_trigger_seek (gpointer userdata);
static gboolean transport_widget_seek (gpointer userdata);
-static gboolean transport_widget_fade_playbutton (gpointer userdata);
/// Init functions //////////////////////////////////////////////////////////
@@ -155,7 +159,11 @@ transport_widget_class_init (TransportWidgetClass *klass)
widget_class->button_release_event = transport_widget_button_release_event;
widget_class->motion_notify_event = transport_widget_motion_notify_event;
widget_class->leave_notify_event = transport_widget_leave_notify_event;
+#if GTK_CHECK_VERSION(3, 0, 0)
+ widget_class->draw = draw;
+#else
widget_class->expose_event = transport_widget_expose;
+#endif
gobject_class->dispose = transport_widget_dispose;
gobject_class->finalize = transport_widget_finalize;
@@ -164,7 +172,25 @@ transport_widget_class_init (TransportWidgetClass *klass)
static void
transport_widget_init (TransportWidget *self)
{
- TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(self);
+ TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(self);
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ if (transport_widget_list == NULL){
+ /* append the object to the static linked list. */
+ transport_widget_list = g_list_append (transport_widget_list, self);
+
+ /* create widget path */
+ spinner_widget_path = gtk_widget_path_new();
+
+ gtk_widget_path_iter_set_name (spinner_widget_path, -1 , "IndicatorSoundSpinner");
+ gtk_widget_path_append_type (spinner_widget_path, GTK_TYPE_SPINNER);
+
+ /* create style context and append path */
+ spinner_style_context = gtk_style_context_new();
+
+ gtk_style_context_set_path (spinner_style_context, spinner_widget_path);
+ gtk_style_context_add_class (spinner_style_context, GTK_STYLE_CLASS_SPINNER);
+ }
+ #endif
priv->current_command = TRANSPORT_ACTION_NO_ACTION;
priv->current_state = TRANSPORT_STATE_PAUSED;
priv->key_event = TRANSPORT_ACTION_NO_ACTION;
@@ -172,9 +198,6 @@ transport_widget_init (TransportWidget *self)
priv->has_focus = FALSE;
priv->hold_timer = 0;
priv->skip_frequency = 0;
- priv->launching_timer = 0;
- priv->launching_transparency = 1.0f;
- priv->fade_out = TRUE;
priv->command_coordinates = g_hash_table_new_full(g_direct_hash,
g_direct_equal,
NULL,
@@ -212,11 +235,11 @@ transport_widget_init (TransportWidget *self)
"notify",
G_CALLBACK (transport_widget_notify),
NULL);
- g_signal_connect (GTK_ITEM(self),
+ g_signal_connect (G_OBJECT(self),
"select",
G_CALLBACK (transport_widget_select),
NULL);
- g_signal_connect (GTK_ITEM(self),
+ g_signal_connect (G_OBJECT(self),
"deselect",
G_CALLBACK (transport_widget_deselect),
NULL);
@@ -227,22 +250,39 @@ transport_widget_init (TransportWidget *self)
static void
transport_widget_dispose (GObject *object)
{
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ transport_widget_list = g_list_remove (transport_widget_list, object);
+
+ if (transport_widget_list == NULL){
+ if (spinner_widget_path != NULL){
+ gtk_widget_path_free (spinner_widget_path);
+ spinner_widget_path = NULL;
+ }
+
+ if (spinner_style_context != NULL){
+ g_object_unref (spinner_style_context);
+ spinner_style_context = NULL;
+ }
+ }
+ #endif
G_OBJECT_CLASS (transport_widget_parent_class)->dispose (object);
}
static void
transport_widget_finalize (GObject *object)
{
+
+
G_OBJECT_CLASS (transport_widget_parent_class)->finalize (object);
}
+#if ! GTK_CHECK_VERSION(3, 0, 0)
static gboolean
transport_widget_expose (GtkWidget *button, GdkEventExpose *event)
{
cairo_t *cr;
- cr = gdk_cairo_create (button->window);
+ cr = gdk_cairo_create (gtk_widget_get_window (button));
- //g_debug("In the playbutton's expose method, x = %i, y=%i and width: %i and height: %i'");
cairo_rectangle (cr,
event->area.x, event->area.y,
event->area.width, event->area.height);
@@ -253,6 +293,7 @@ transport_widget_expose (GtkWidget *button, GdkEventExpose *event)
cairo_destroy (cr);
return FALSE;
}
+#endif
gboolean
transport_widget_is_selected ( TransportWidget* widget )
@@ -267,7 +308,6 @@ transport_widget_toggle_play_pause(TransportWidget* button,
{
TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(button);
priv->current_state = update;
- //g_debug("TransportWidget::toggle play state : %i", priv->current_state);
gtk_widget_queue_draw (GTK_WIDGET(button));
}
@@ -298,6 +338,8 @@ static gboolean
transport_widget_motion_notify_event (GtkWidget *menuitem,
GdkEventMotion *event)
{
+ //g_debug("transport_widget_motion_notify_event()");
+
g_return_val_if_fail ( IS_TRANSPORT_WIDGET(menuitem), FALSE );
TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE ( TRANSPORT_WIDGET(menuitem) );
TransportAction result = transport_widget_determine_motion_event ( TRANSPORT_WIDGET(menuitem),
@@ -319,6 +361,8 @@ static gboolean
transport_widget_leave_notify_event (GtkWidget *menuitem,
GdkEventCrossing *event)
{
+ //g_debug("transport_widget_leave_notify_event()");
+
g_return_val_if_fail ( IS_TRANSPORT_WIDGET(menuitem), FALSE );
TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE ( TRANSPORT_WIDGET(menuitem) );
@@ -333,6 +377,8 @@ static gboolean
transport_widget_button_press_event (GtkWidget *menuitem,
GdkEventButton *event)
{
+ //g_debug("transport_widget_button_press_event()");
+
g_return_val_if_fail ( IS_TRANSPORT_WIDGET(menuitem), FALSE );
TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE ( TRANSPORT_WIDGET(menuitem) );
TransportAction result = transport_widget_determine_button_event ( TRANSPORT_WIDGET(menuitem),
@@ -434,7 +480,7 @@ transport_widget_button_release_event (GtkWidget *menuitem,
}
static void
-transport_widget_select (GtkItem* item, gpointer Userdata)
+transport_widget_select (GtkWidget* item, gpointer Userdata)
{
TransportWidget* transport = TRANSPORT_WIDGET(item);
TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport );
@@ -442,7 +488,7 @@ transport_widget_select (GtkItem* item, gpointer Userdata)
}
static void
-transport_widget_deselect (GtkItem* item, gpointer Userdata)
+transport_widget_deselect (GtkWidget* item, gpointer Userdata)
{
TransportWidget* transport = TRANSPORT_WIDGET(item);
TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport );
@@ -1214,23 +1260,30 @@ _surface_blur (cairo_surface_t* surface,
cairo_surface_mark_dirty (surface);
}
-static void
+static gboolean
draw (GtkWidget* button, cairo_t *cr)
{
- g_return_if_fail(IS_TRANSPORT_WIDGET(button));
- g_return_if_fail( cr != NULL );
+ g_return_val_if_fail(IS_TRANSPORT_WIDGET(button), FALSE);
+ g_return_val_if_fail(cr != NULL, FALSE);
TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(button);
-
+
+ //g_debug("transport-widget draw()");
+
cairo_surface_t* surf = NULL;
cairo_t* cr_surf = NULL;
- cairo_translate (cr, button->allocation.x, button->allocation.y);
-
- //g_debug("button x allocation = %i", button->allocation.x);
- //g_debug("button y allocation = %i", button->allocation.y);
+#if ! GTK_CHECK_VERSION(3, 0, 0)
+ GtkAllocation allocation;
+ gtk_widget_get_allocation (button, &allocation);
+ cairo_translate (cr, allocation.x, allocation.y);
+#endif
GtkStyle *style;
-
+
+#if GTK_CHECK_VERSION(3, 0, 0)
+ gtk_style_context_add_class (gtk_widget_get_style_context (button),
+ "menu");
+#endif
CairoColorRGB bg_color, fg_color, bg_selected, bg_prelight;
CairoColorRGB color_middle[2], color_middle_prelight[2], color_outer[2], color_outer_prelight[2],
color_play_outer[2], color_play_outer_prelight[2],
@@ -1740,61 +1793,14 @@ draw (GtkWidget* button, cairo_t *cr)
FALSE);
_finalize (cr, &cr_surf, &surf, PAUSE_X-0.5f, PAUSE_Y);
}
+ #if GTK_CHECK_VERSION(3, 0, 0)
else if(priv->current_state == TRANSPORT_STATE_LAUNCHING)
{
-/*
- g_debug ("launching in draw");
-*/
- _setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6);
- _mask_play (cr_surf,
- PLAY_PADDING,
- PLAY_PADDING,
- PLAY_WIDTH - (2*PLAY_PADDING),
- PLAY_HEIGHT - (2*PLAY_PADDING));
-
- double BUTTON_SHADOW_LAUNCHING[] = {color_button[3].r,
- color_button[3].g,
- color_button[3].b,
- priv->launching_transparency};
- double BUTTON_LAUNCHING_END[] = {color_button[0].r,
- color_button[0].g,
- color_button[0].b,
- priv->launching_transparency};
- double BUTTON_LAUNCHING_START[] = {color_button[1].r,
- color_button[1].g,
- color_button[1].b,
- priv->launching_transparency};
- _fill (cr_surf,
- PLAY_PADDING,
- PLAY_PADDING,
- PLAY_WIDTH - (2*PLAY_PADDING),
- PLAY_HEIGHT - (2*PLAY_PADDING),
- BUTTON_SHADOW_LAUNCHING,
- BUTTON_SHADOW_LAUNCHING,
- FALSE);
- _surface_blur (surf, 3);
- _finalize_repaint (cr, &cr_surf, &surf, PAUSE_X-0.5f, PAUSE_Y + 0.5f, 3);
- // draw play-button
- _setup (&cr_surf, &surf, PLAY_WIDTH, PLAY_HEIGHT);
- cairo_set_line_width (cr, 10.5);
- cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
- cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
- _mask_play (cr_surf,
- PLAY_PADDING,
- PLAY_PADDING,
- PLAY_WIDTH - (2*PLAY_PADDING),
- PLAY_HEIGHT - (2*PLAY_PADDING));
- _fill (cr_surf,
- PLAY_PADDING,
- PLAY_PADDING,
- PLAY_WIDTH - (2*PLAY_PADDING),
- PLAY_HEIGHT - (2*PLAY_PADDING),
- BUTTON_LAUNCHING_START,
- BUTTON_LAUNCHING_END,
- FALSE);
- _finalize (cr, &cr_surf, &surf, PAUSE_X-0.5f, PAUSE_Y);
+ gtk_render_activity (spinner_style_context, cr, 106, 6 , 30, 30);
}
+ #endif
+ return FALSE;
}
static void
@@ -1812,30 +1818,6 @@ transport_widget_set_twin_item(TransportWidget* self,
(TransportState)initial_state);
}
-static gboolean
-transport_widget_fade_playbutton (gpointer userdata)
-{
- TransportWidget* bar = (TransportWidget*)userdata;
- g_return_val_if_fail(IS_TRANSPORT_WIDGET(bar), FALSE);
-/*
- g_debug ("fade in /out timeout");
-*/
- TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(bar);
- if (priv->launching_transparency == 1.0f){
- priv->fade_out = TRUE;
- }
- else if (priv->launching_transparency <= 0.3F){
- priv->fade_out = FALSE;
- }
- if (priv->fade_out == TRUE){
- priv->launching_transparency -= 0.05f;
- }
- else{
- priv->launching_transparency += 0.05f;
- }
- gtk_widget_queue_draw (GTK_WIDGET(bar));
- return TRUE;
-}
/**
* transport_widget_update_state()
* Callback for updates from the other side of dbus
@@ -1852,21 +1834,21 @@ transport_widget_property_update(DbusmenuMenuitem* item, gchar* property,
if(g_ascii_strcasecmp(DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE, property) == 0)
{
TransportState new_state = (TransportState)g_variant_get_int32(value);
- //g_debug("transport_widget_update_state - with value %i", update_value);
+ //g_debug("transport_widget_update_state - with value %i", new_state);
if (new_state == TRANSPORT_STATE_LAUNCHING){
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ gtk_style_context_notify_state_change (spinner_style_context,
+ gtk_widget_get_window ( GTK_WIDGET(userdata)),
+ NULL,
+ GTK_STATE_FLAG_ACTIVE,
+ TRUE);
+ gtk_style_context_set_state (spinner_style_context, GTK_STATE_FLAG_ACTIVE);
+ #endif
+
priv->current_state = TRANSPORT_STATE_LAUNCHING;
- priv->launching_timer = g_timeout_add (100,
- transport_widget_fade_playbutton,
- bar);
- //g_debug("TransportWidget::toggle play state : %i", priv->current_state);
+ g_debug("TransportWidget::toggle play state : %i", priv->current_state);
}
else{
- if (priv->launching_timer != 0){
- g_source_remove (priv->launching_timer);
- priv->launching_timer = 0;
- priv->fade_out = TRUE;
- priv->launching_transparency = 1.0f;
- }
transport_widget_toggle_play_pause(bar, new_state);
}
}