ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #01900
[Merge] lp:~cjcurran/indicator-sound/play_button into lp:indicator-sound
Conor Curran has proposed merging lp:~cjcurran/indicator-sound/play_button into lp:indicator-sound.
Requested reviews:
Indicator Applet Developers (indicator-applet-developers)
Play button now drawn properly.
Each button press/unpress now clipped on redraw.
--
https://code.launchpad.net/~cjcurran/indicator-sound/play_button/+merge/30377
Your team ayatana-commits is subscribed to branch lp:indicator-sound.
=== modified file 'src/mpris-controller.vala'
--- src/mpris-controller.vala 2010-07-15 12:23:52 +0000
+++ src/mpris-controller.vala 2010-07-20 10:35:52 +0000
@@ -29,9 +29,9 @@
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 @@
}
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 @@
}
- 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 @@
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 @@
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());
+ }
+
}
=== modified file 'src/play-button.c'
--- src/play-button.c 2010-07-15 14:51:45 +0000
+++ src/play-button.c 2010-07-20 10:35:52 +0000
@@ -52,13 +52,9 @@
#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 @@
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 @@
/// internal helper functions //////////////////////////////////////////////////
-static double
+/*static double
_align (double val)
{
double fract = val - (int) val;
@@ -96,7 +94,7 @@
return (double) ((int) val + 0.5f);
else
return val;
-}
+}*/
static inline void
_blurinner (guchar* pixel,
@@ -309,8 +307,7 @@
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 @@
{
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 @@
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 @@
{
g_return_if_fail(IS_PLAY_BUTTON(button));
PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button);
+ cairo_t *cr;
+
+ cr = gdk_cairo_create (button->window);
+ GList* list = g_hash_table_lookup(priv->command_coordinates,
+ GINT_TO_POINTER(priv->current_command));
+
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);
-
- cairo_clip(cr);*/
+
+ 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);
}
-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 @@
}
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 @@
_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);
+ }
+
}
=== modified file 'src/play-button.h'
--- src/play-button.h 2010-07-15 14:46:54 +0000
+++ src/play-button.h 2010-07-20 10:35:52 +0000
@@ -40,6 +40,11 @@
TRANSPORT_NADA
}PlayButtonEvent;
+typedef enum {
+ PLAY,
+ PAUSE
+}PlayButtonState;
+
struct _PlayButtonClass {
GtkDrawingAreaClass parent_class;
};
@@ -53,7 +58,7 @@
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();
=== modified file 'src/transport-widget.c'
--- src/transport-widget.c 2010-07-15 14:46:54 +0000
+++ src/transport-widget.c 2010-07-20 10:35:52 +0000
@@ -186,7 +186,7 @@
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);
}
/**
Follow ups