diff options
-rw-r--r-- | src/mpris-controller.vala | 57 | ||||
-rw-r--r-- | src/play-button.c | 222 | ||||
-rw-r--r-- | src/play-button.h | 7 | ||||
-rw-r--r-- | src/transport-widget.c | 2 |
4 files changed, 193 insertions, 95 deletions
diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index 5e4dce2..8e43131 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -29,9 +29,9 @@ public class MprisController : GLib.Object struct status { public int32 playback; - //public int32 shuffle; // Not used just yet - //public int32 repeat; - //public int32 endless; + public int32 shuffle; + public int32 repeat; + public int32 endless; } public MprisController(PlayerController ctrl, string inter="org.freedesktop.MediaPlayer"){ @@ -46,7 +46,7 @@ public class MprisController : GLib.Object } this.mpris_player = this.connection.get_object ("org.mpris.".concat(this.owner.name.down()) , "/Player", this.mpris_interface); - debug("just attempting to establish an mpris connection to %s, %s, %s", "org.mpris.".concat(this.owner.name.down()) , "/Player", this.mpris_interface); + debug("Attempting to establish an mpris connection to %s, %s, %s", "org.mpris.".concat(this.owner.name.down()) , "/Player", this.mpris_interface); this.mpris_player.TrackChange += onTrackChange; this.mpris_player.StatusChange += onStatusChange; @@ -69,38 +69,12 @@ public class MprisController : GLib.Object } - private void onTrackChange(dynamic DBus.Object mpris_client, HashTable<string,Value?> ht) - { - debug("onTrackChange"); - this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, - MetadataMenuitem.attributes_format()); - debug("about to update the duration on the scrub bar"); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), - ScrubMenuitem.attributes_format()); - // temporary fix - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris_player.PositionGet()); - } - public void transport_event(TransportMenuitem.action command) { debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ - status st = this.mpris_player.GetStatus(); - bool play_state = st.playback == 1; - debug("toggle_playback - initial play state %i", (int)play_state); - bool new_play_state = !play_state; - debug("toggle_playback - new play state %i", (int)new_play_state); - if(new_play_state == true){ - debug("about to play"); - this.mpris_player.Play(); - } - else{ - debug("about to pause"); - this.mpris_player.Pause(); - } + debug("transport_event PLAY_PAUSE"); + this.mpris_player.Pause(); } else if(command == TransportMenuitem.action.PREVIOUS){ this.mpris_player.Prev(); @@ -133,7 +107,7 @@ public class MprisController : GLib.Object private void onStatusChange(dynamic DBus.Object mpris_client, status st) { - debug("onStatusChange - signal received"); + debug("onStatusChange - signal received"); status* status = &st; unowned ValueArray ar = (ValueArray)status; int play_state = ar.get_nth(0).get_int(); @@ -144,6 +118,21 @@ public class MprisController : GLib.Object ht.insert("state", v); this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); } - + + private void onTrackChange(dynamic DBus.Object mpris_client, HashTable<string,Value?> ht) + { + debug("onTrackChange"); + this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, + MetadataMenuitem.attributes_format()); + debug("about to update the duration on the scrub bar"); + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), + ScrubMenuitem.attributes_format()); + // temporary fix + ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + scrub.update_position(this.mpris_player.PositionGet()); + } + } diff --git a/src/play-button.c b/src/play-button.c index cac2bc3..539b2b2 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -52,13 +52,9 @@ Uses code from ctk #define BAR_OFFSET 10.0f #define PAUSE_X 77.0f #define PAUSE_Y 15.0f - - -// Transport updates -enum{ - PAUSE, - PLAY -}; +#define PLAY_WIDTH 28.0f +#define PLAY_HEIGHT 29.0f +#define PLAY_PADDING 5.0f typedef struct _PlayButtonPrivate PlayButtonPrivate; @@ -70,6 +66,8 @@ struct _PlayButtonPrivate GdkColor foreground_colour_fg; GdkColor foreground_colour_bg; PlayButtonEvent current_command; + PlayButtonState current_state; + GHashTable* command_coordinates; }; #define PLAY_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAY_BUTTON_TYPE, PlayButtonPrivate)) @@ -87,7 +85,7 @@ G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); /// internal helper functions ////////////////////////////////////////////////// -static double +/*static double _align (double val) { double fract = val - (int) val; @@ -96,7 +94,7 @@ _align (double val) return (double) ((int) val + 0.5f); else return val; -} +}*/ static inline void _blurinner (guchar* pixel, @@ -309,8 +307,7 @@ _surface_blur (cairo_surface_t* surface, static void play_button_class_init (PlayButtonClass *klass) -{ - +{ GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); @@ -327,6 +324,41 @@ play_button_init (PlayButton *self) { PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(self); priv->current_command = TRANSPORT_NADA; + priv->current_state = PAUSE; + priv->command_coordinates = g_hash_table_new_full(g_direct_hash, + g_direct_equal, + NULL, + g_list_free); + GList* previous_list = NULL; + previous_list = g_list_insert(previous_list, GINT_TO_POINTER(15), 0); + previous_list = g_list_insert(previous_list, GINT_TO_POINTER(10), 1); + previous_list = g_list_insert(previous_list, GINT_TO_POINTER(60), 2); + previous_list = g_list_insert(previous_list, GINT_TO_POINTER(34), 3); + + g_hash_table_insert(priv->command_coordinates, + GINT_TO_POINTER(TRANSPORT_PREVIOUS), + previous_list); + + GList* play_list = NULL; + play_list = g_list_insert(play_list, GINT_TO_POINTER(60), 0); + play_list = g_list_insert(play_list, GINT_TO_POINTER(10), 1); + play_list = g_list_insert(play_list, GINT_TO_POINTER(45), 2); + play_list = g_list_insert(play_list, GINT_TO_POINTER(40), 3); + + g_hash_table_insert(priv->command_coordinates, + GINT_TO_POINTER(TRANSPORT_PLAY_PAUSE), + play_list); + + GList* next_list = NULL; + next_list = g_list_insert(next_list, GINT_TO_POINTER(100), 0); + next_list = g_list_insert(next_list, GINT_TO_POINTER(10), 1); + next_list = g_list_insert(next_list, GINT_TO_POINTER(60), 2); + next_list = g_list_insert(next_list, GINT_TO_POINTER(34), 3); + + g_hash_table_insert(priv->command_coordinates, + GINT_TO_POINTER(TRANSPORT_NEXT), + next_list); + gtk_widget_set_size_request(GTK_WIDGET(self), 200, 80); } @@ -391,12 +423,13 @@ play_button_react_to_button_press(GtkWidget* button, PlayButtonEvent command) cairo_t *cr; cr = gdk_cairo_create (button->window); - - /*cairo_rectangle (cr, - event->area.x, event->area.y, - event->area.width, event->area.height); - - cairo_clip(cr);*/ + GList* list = g_hash_table_lookup(priv->command_coordinates, GINT_TO_POINTER(command)); + cairo_rectangle(cr, + GPOINTER_TO_INT(g_list_nth_data(list, 0)), + GPOINTER_TO_INT(g_list_nth_data(list, 1)), + GPOINTER_TO_INT(g_list_nth_data(list, 2)), + GPOINTER_TO_INT(g_list_nth_data(list, 3))); + cairo_clip(cr); draw (button, cr); cairo_destroy (cr); } @@ -407,22 +440,32 @@ play_button_react_to_button_release(GtkWidget* button) { g_return_if_fail(IS_PLAY_BUTTON(button)); PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); - priv->current_command = TRANSPORT_NADA; cairo_t *cr; + cr = gdk_cairo_create (button->window); - /*cairo_rectangle (cr, - event->area.x, event->area.y, - event->area.width, event->area.height); + GList* list = g_hash_table_lookup(priv->command_coordinates, + GINT_TO_POINTER(priv->current_command)); + + priv->current_command = TRANSPORT_NADA; + + cairo_rectangle(cr, + GPOINTER_TO_INT(g_list_nth_data(list, 0)), + GPOINTER_TO_INT(g_list_nth_data(list, 1)), + GPOINTER_TO_INT(g_list_nth_data(list, 2)), + GPOINTER_TO_INT(g_list_nth_data(list, 3))); - cairo_clip(cr);*/ + cairo_clip(cr); draw (button, cr); cairo_destroy (cr); } -void -play_button_toggle_play_pause(GtkWidget* button, int update) +void +play_button_toggle_play_pause(GtkWidget* button, PlayButtonState update) { + PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); + priv->current_state = update; + g_debug("PlayButton::toggle play state : %i", priv->current_state); } @@ -608,6 +651,24 @@ _mask_pause (cairo_t* cr, } static void +_mask_play (cairo_t* cr, + double x, + double y, + double tri_width, + double tri_height + /*double tri_offset*/) +{ + if (!cr) + return; + + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + tri_width, y + tri_height / 2.0f); + cairo_line_to (cr, x, y + tri_height); + cairo_close_path (cr); + +} + +static void _fill (cairo_t* cr, double x_start, double y_start, @@ -826,41 +887,84 @@ draw (GtkWidget* button, cairo_t *cr) _finalize (cr, &cr_surf, &surf, NEXT_X, NEXT_Y); // draw pause-button drop-shadow - _setup (&cr_surf, &surf, PAUSE_WIDTH, PAUSE_HEIGHT); - _mask_pause (cr_surf, - (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, - (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, - BAR_WIDTH, - BAR_HEIGHT - 2.0f * BAR_WIDTH, - BAR_OFFSET); - _fill (cr_surf, - (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, - (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, - (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, - (double) BAR_HEIGHT, - BUTTON_SHADOW, - BUTTON_SHADOW, - TRUE); - _surface_blur (surf, 1); - _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y + 1.0f); - - // draw pause-button - _setup (&cr_surf, &surf, PAUSE_WIDTH, PAUSE_HEIGHT); - _mask_pause (cr_surf, - (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, - (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, - BAR_WIDTH, - BAR_HEIGHT - 2.0f * BAR_WIDTH, - BAR_OFFSET); - _fill (cr_surf, - (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, - (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, - (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, - (double) BAR_HEIGHT, - BUTTON_START, - BUTTON_END, - TRUE); - _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y); + if(priv->current_state == PLAY){ + _setup (&cr_surf, &surf, PAUSE_WIDTH, PAUSE_HEIGHT); + _mask_pause (cr_surf, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + BAR_WIDTH, + BAR_HEIGHT - 2.0f * BAR_WIDTH, + BAR_OFFSET); + _fill (cr_surf, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (double) BAR_HEIGHT, + BUTTON_SHADOW, + BUTTON_SHADOW, + TRUE); + _surface_blur (surf, 1); + _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y + 1.0f); + + // draw pause-button + _setup (&cr_surf, &surf, PAUSE_WIDTH, PAUSE_HEIGHT); + _mask_pause (cr_surf, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + BAR_WIDTH, + BAR_HEIGHT - 2.0f * BAR_WIDTH, + BAR_OFFSET); + _fill (cr_surf, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (double) BAR_HEIGHT, + BUTTON_START, + BUTTON_END, + TRUE); + _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y); + } + else if(priv->current_state == PAUSE){ + _setup (&cr_surf, &surf, PLAY_WIDTH, PLAY_HEIGHT); + _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_SHADOW, + BUTTON_SHADOW, + FALSE); + cairo_surface_write_to_png(surf, "/tmp/drop_shadow.png"); + _surface_blur (surf, 1); + _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y + 1.0f); + // 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_START, + BUTTON_END, + FALSE); + cairo_surface_write_to_png(surf, "/tmp/play.png"); + + _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y); + } + } diff --git a/src/play-button.h b/src/play-button.h index 6f646b5..727a489 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -40,6 +40,11 @@ typedef enum { TRANSPORT_NADA }PlayButtonEvent; +typedef enum { + PLAY, + PAUSE +}PlayButtonState; + struct _PlayButtonClass { GtkDrawingAreaClass parent_class; }; @@ -53,7 +58,7 @@ void play_button_set_style(GtkWidget* button, GtkStyle* style); PlayButtonEvent determine_button_event(GtkWidget* button, GdkEventButton* event); void play_button_react_to_button_press(GtkWidget* button, PlayButtonEvent command); void play_button_react_to_button_release(GtkWidget* button); -void play_button_toggle_play_pause(GtkWidget* button, int update); +void play_button_toggle_play_pause(GtkWidget* button, PlayButtonState update); GtkWidget* play_button_new(); diff --git a/src/transport-widget.c b/src/transport-widget.c index 3174afe..c616fff 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -186,7 +186,7 @@ transport_widget_property_update(DbusmenuMenuitem* item, gchar* property, TransportWidgetPrivate *priv = TRANSPORT_WIDGET_GET_PRIVATE(bar); int update_value = g_value_get_int(value); g_debug("transport_widget_update_state - with value %i", update_value); - play_button_toggle_play_pause(priv->play_button, update_value); + play_button_toggle_play_pause(priv->play_button, (PlayButtonState)update_value); } /** |