aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Bacher <seb128@ubuntu.com>2010-09-08 19:51:33 +0200
committerSebastien Bacher <seb128@ubuntu.com>2010-09-08 19:51:33 +0200
commitd1fd48d0ed8ce30d29c424c9ff12d9b02a744f52 (patch)
tree7855b6beeae39a8af9f1edc22dbf8b0dc82f0dbf /src
parent7e9c9ed5e67bf26226996dda674ac4e4c5b4b272 (diff)
parent75f6c6bfa400649014ed90d87e57d5bf4b542f31 (diff)
downloadayatana-indicator-sound-d1fd48d0ed8ce30d29c424c9ff12d9b02a744f52.tar.gz
ayatana-indicator-sound-d1fd48d0ed8ce30d29c424c9ff12d9b02a744f52.tar.bz2
ayatana-indicator-sound-d1fd48d0ed8ce30d29c424c9ff12d9b02a744f52.zip
releasing version 0.4.3-0ubuntu1
Diffstat (limited to 'src')
-rw-r--r--src/common-defs.h1
-rw-r--r--src/indicator-sound.c29
-rw-r--r--src/mpris2-controller.c40
-rw-r--r--src/mpris2-controller.vala22
-rw-r--r--src/music-player-bridge.h11
-rw-r--r--src/play-button.c11
-rw-r--r--src/player-controller.c29
-rw-r--r--src/player-controller.vala6
-rw-r--r--src/title-menu-item.c8
-rw-r--r--src/title-menu-item.vala7
-rw-r--r--src/title-widget.c130
-rw-r--r--src/title-widget.h6
-rw-r--r--src/transport-menu-item.c30
-rw-r--r--src/transport-menu-item.vala11
14 files changed, 241 insertions, 100 deletions
diff --git a/src/common-defs.h b/src/common-defs.h
index e554c11..e268aaa 100644
--- a/src/common-defs.h
+++ b/src/common-defs.h
@@ -41,6 +41,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define DBUSMENU_TITLE_MENUITEM_TYPE "x-canonical-sound-menu-player-title-type"
#define DBUSMENU_TITLE_MENUITEM_NAME "x-canonical-sound-menu-player-title-name"
+#define DBUSMENU_TITLE_MENUITEM_RUNNING "x-canonical-sound-menu-player-title-running"
#define DBUSMENU_SCRUB_MENUITEM_TYPE "x-canonical-sound-menu-player-scrub-type"
#define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-mpris:length"
diff --git a/src/indicator-sound.c b/src/indicator-sound.c
index b59eb98..0e631fa 100644
--- a/src/indicator-sound.c
+++ b/src/indicator-sound.c
@@ -196,8 +196,10 @@ get_label (IndicatorObject * io)
static GtkImage *
get_icon (IndicatorObject * io)
{
- gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
- g_debug("At start-up attempting to set the image to %s", current_name);
+ gchar* current_name = g_hash_table_lookup(volume_states,
+ GINT_TO_POINTER(current_state));
+ g_debug("At start-up attempting to set the image to %s",
+ current_name);
speaker_image = indicator_image_helper(current_name);
gtk_widget_show(GTK_WIDGET(speaker_image));
return speaker_image;
@@ -209,7 +211,8 @@ get_icon (IndicatorObject * io)
static GtkMenu *
get_menu (IndicatorObject * io)
{
- DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT);
+ DbusmenuGtkMenu* menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT);
+
DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu);
g_object_set_data (G_OBJECT (client), "indicator", io);
dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_VOLUME_MENUITEM_TYPE, new_volume_slider_widget);
@@ -217,10 +220,10 @@ get_menu (IndicatorObject * io)
dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget);
dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget);
dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SCRUB_MENUITEM_TYPE, new_scrub_bar_widget);
-
// register Key-press listening on the menu widget as the slider does not allow this.
g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), io);
- return GTK_MENU(menu);
+
+ return GTK_MENU(menu);
}
static void
@@ -274,20 +277,22 @@ new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm
static gboolean
new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
{
- g_debug("indicator-sound: new_title_widget");
-
- GtkWidget* title = NULL;
-
+ g_debug("indicator-sound: new_title_widget");
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);
+ g_debug ("%s (\"%s\")", __func__, dbusmenu_menuitem_property_get(newitem, DBUSMENU_TITLE_MENUITEM_NAME));
+
+ GtkWidget* title = NULL;
+
title = title_widget_new (newitem);
GtkMenuItem *menu_title_widget = GTK_MENU_ITEM(title);
-
+
gtk_widget_show_all(title);
- dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_title_widget, parent);
-
+ dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
+ newitem,
+ menu_title_widget, parent);
return TRUE;
}
diff --git a/src/mpris2-controller.c b/src/mpris2-controller.c
index 6aa2be2..ff75bd2 100644
--- a/src/mpris2-controller.c
+++ b/src/mpris2-controller.c
@@ -91,6 +91,8 @@ typedef struct _Mpris2ControllerPrivate Mpris2ControllerPrivate;
typedef struct _PlayerController PlayerController;
typedef struct _PlayerControllerClass PlayerControllerClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
+
+#define TRANSPORT_MENUITEM_TYPE_STATE (transport_menuitem_state_get_type ())
typedef struct _PlayerControllerPrivate PlayerControllerPrivate;
#define TYPE_PLAYER_ITEM (player_item_get_type ())
@@ -190,6 +192,11 @@ struct _Mpris2ControllerPrivate {
FreeDesktopProperties* _properties_interface;
};
+typedef enum {
+ TRANSPORT_MENUITEM_STATE_PLAYING,
+ TRANSPORT_MENUITEM_STATE_PAUSED
+} TransportMenuitemstate;
+
struct _PlayerController {
GObject parent_instance;
PlayerControllerPrivate * priv;
@@ -351,11 +358,12 @@ void mpris2_controller_property_changed_cb (Mpris2Controller* self, const char*
PlayerController* mpris2_controller_get_owner (Mpris2Controller* self);
const char* player_controller_get_name (PlayerController* self);
static GValue* _g_value_dup (GValue* self);
-static gint mpris2_controller_determine_play_state (Mpris2Controller* self, const char* status);
+GType transport_menuitem_state_get_type (void) G_GNUC_CONST;
+static TransportMenuitemstate mpris2_controller_determine_play_state (Mpris2Controller* self, const char* status);
GType player_item_get_type (void) G_GNUC_CONST;
GType player_controller_widget_order_get_type (void) G_GNUC_CONST;
GType transport_menuitem_get_type (void) G_GNUC_CONST;
-void transport_menuitem_change_play_state (TransportMenuitem* self, gint state);
+void transport_menuitem_change_play_state (TransportMenuitem* self, TransportMenuitemstate update);
static GHashTable* mpris2_controller_clean_metadata (Mpris2Controller* self);
void player_item_reset (PlayerItem* self, GeeHashSet* attrs);
GeeHashSet* metadata_menuitem_attributes_format (void);
@@ -4691,12 +4699,12 @@ void mpris2_controller_property_changed_cb (Mpris2Controller* self, const char*
play_v = __g_value_dup0 ((GValue*) g_hash_table_lookup (changed_properties, "PlaybackStatus"));
if (play_v != NULL) {
char* state;
- gint p;
+ TransportMenuitemstate p;
PlayerItem* _tmp2_;
TransportMenuitem* _tmp3_;
state = g_strdup (g_value_get_string (play_v));
g_debug ("mpris2-controller.vala:107: new playback state = %s", state);
- p = mpris2_controller_determine_play_state (self, state);
+ p = (TransportMenuitemstate) mpris2_controller_determine_play_state (self, state);
transport_menuitem_change_play_state (_tmp3_ = (_tmp2_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TRANSPORT), IS_TRANSPORT_MENUITEM (_tmp2_) ? ((TransportMenuitem*) _tmp2_) : NULL), p);
_g_object_unref0 (_tmp3_);
_g_free0 (state);
@@ -4785,13 +4793,13 @@ static GHashTable* mpris2_controller_clean_metadata (Mpris2Controller* self) {
}
-static gint mpris2_controller_determine_play_state (Mpris2Controller* self, const char* status) {
- gint result = 0;
+static TransportMenuitemstate mpris2_controller_determine_play_state (Mpris2Controller* self, const char* status) {
+ TransportMenuitemstate result = 0;
gboolean _tmp0_ = FALSE;
g_return_val_if_fail (self != NULL, 0);
g_return_val_if_fail (status != NULL, 0);
if (status == NULL) {
- result = 1;
+ result = TRANSPORT_MENUITEM_STATE_PAUSED;
return result;
}
if (status != NULL) {
@@ -4801,16 +4809,16 @@ static gint mpris2_controller_determine_play_state (Mpris2Controller* self, cons
}
if (_tmp0_) {
g_debug ("mpris2-controller.vala:151: determine play state - state = %s", status);
- result = 0;
+ result = TRANSPORT_MENUITEM_STATE_PLAYING;
return result;
}
- result = 1;
+ result = TRANSPORT_MENUITEM_STATE_PAUSED;
return result;
}
void mpris2_controller_initial_update (Mpris2Controller* self) {
- gint32 status = 0;
+ TransportMenuitemstate update = 0;
char* _tmp0_;
gboolean _tmp1_;
PlayerItem* _tmp3_;
@@ -4820,14 +4828,14 @@ void mpris2_controller_initial_update (Mpris2Controller* self) {
GeeHashSet* _tmp6_;
g_return_if_fail (self != NULL);
if ((_tmp1_ = (_tmp0_ = mpris_player_get_PlaybackStatus (self->priv->_player)) == NULL, _g_free0 (_tmp0_), _tmp1_)) {
- status = (gint32) 1;
+ update = TRANSPORT_MENUITEM_STATE_PAUSED;
} else {
char* _tmp2_;
- status = (gint32) mpris2_controller_determine_play_state (self, _tmp2_ = mpris_player_get_PlaybackStatus (self->priv->_player));
+ update = mpris2_controller_determine_play_state (self, _tmp2_ = mpris_player_get_PlaybackStatus (self->priv->_player));
_g_free0 (_tmp2_);
}
- g_debug ("mpris2-controller.vala:166: initial update - play state %i", (gint) status);
- transport_menuitem_change_play_state (_tmp4_ = (_tmp3_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TRANSPORT), IS_TRANSPORT_MENUITEM (_tmp3_) ? ((TransportMenuitem*) _tmp3_) : NULL), (gint) status);
+ g_debug ("mpris2-controller.vala:166: initial update - play state %i", (gint) update);
+ transport_menuitem_change_play_state (_tmp4_ = (_tmp3_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TRANSPORT), IS_TRANSPORT_MENUITEM (_tmp3_) ? ((TransportMenuitem*) _tmp3_) : NULL), update);
_g_object_unref0 (_tmp4_);
cleaned_metadata = mpris2_controller_clean_metadata (self);
player_item_update (_tmp5_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_METADATA), cleaned_metadata, _tmp6_ = metadata_menuitem_attributes_format ());
@@ -5075,8 +5083,8 @@ void mpris2_controller_expose (Mpris2Controller* self) {
e = _inner_error_;
_inner_error_ = NULL;
{
- g_error ("mpris2-controller.vala:263: Exception thrown while calling root functi" \
-"on Raise - %s", e->message);
+ g_error ("mpris2-controller.vala:263: Exception thrown while calling function Ra" \
+"ise - %s", e->message);
_g_error_free0 (e);
}
}
diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala
index cf5a39e..dab5e2c 100644
--- a/src/mpris2-controller.vala
+++ b/src/mpris2-controller.vala
@@ -105,7 +105,7 @@ public class Mpris2Controller : GLib.Object
if(play_v != null){
string state = play_v.get_string();
debug("new playback state = %s", state);
- int p = this.determine_play_state(state);
+ TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(state);
(this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p);
}
@@ -143,29 +143,29 @@ public class Mpris2Controller : GLib.Object
}
- private int determine_play_state(string status){
+ private TransportMenuitem.state determine_play_state(string status){
if(status == null)
- return 1;
+ return TransportMenuitem.state.PAUSED;
if(status != null && status == "Playing"){
debug("determine play state - state = %s", status);
- return 0;
+ return TransportMenuitem.state.PLAYING;
}
- return 1;
+ return TransportMenuitem.state.PAUSED;
}
public void initial_update()
{
- int32 status;
+ TransportMenuitem.state update;
if(this.player.PlaybackStatus == null){
- status = 1;
+ update = TransportMenuitem.state.PAUSED;
}
else{
- status = determine_play_state(this.player.PlaybackStatus);
+ update = determine_play_state(this.player.PlaybackStatus);
}
- debug("initial update - play state %i", status);
+ debug("initial update - play state %i", (int)update);
- (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status);
+ (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(update);
GLib.HashTable<string, Value?> cleaned_metadata = this.clean_metadata();
this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata,
MetadataMenuitem.attributes_format());
@@ -260,7 +260,7 @@ public class Mpris2Controller : GLib.Object
this.mpris2_root.Raise();
}
catch(DBus.Error e){
- error("Exception thrown while calling root function Raise - %s", e.message);
+ error("Exception thrown while calling function Raise - %s", e.message);
}
}
}
diff --git a/src/music-player-bridge.h b/src/music-player-bridge.h
index d1a612f..70f8e6c 100644
--- a/src/music-player-bridge.h
+++ b/src/music-player-bridge.h
@@ -62,6 +62,8 @@ typedef struct _TransportMenuitemPrivate TransportMenuitemPrivate;
#define TRANSPORT_MENUITEM_TYPE_ACTION (transport_menuitem_action_get_type ())
+#define TRANSPORT_MENUITEM_TYPE_STATE (transport_menuitem_state_get_type ())
+
#define TYPE_PLAYER_CONTROLLER (player_controller_get_type ())
#define PLAYER_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLAYER_CONTROLLER, PlayerController))
#define PLAYER_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLAYER_CONTROLLER, PlayerControllerClass))
@@ -200,6 +202,11 @@ typedef enum {
TRANSPORT_MENUITEM_ACTION_NEXT
} TransportMenuitemaction;
+typedef enum {
+ TRANSPORT_MENUITEM_STATE_PLAYING,
+ TRANSPORT_MENUITEM_STATE_PAUSED
+} TransportMenuitemstate;
+
struct _MetadataMenuitem {
PlayerItem parent_instance;
MetadataMenuitemPrivate * priv;
@@ -331,10 +338,11 @@ GAppInfo* music_player_bridge_create_app_info (const char* path);
GType player_item_get_type (void) G_GNUC_CONST;
GType transport_menuitem_get_type (void) G_GNUC_CONST;
GType transport_menuitem_action_get_type (void) G_GNUC_CONST;
+GType transport_menuitem_state_get_type (void) G_GNUC_CONST;
GType player_controller_get_type (void) G_GNUC_CONST;
TransportMenuitem* transport_menuitem_new (PlayerController* parent);
TransportMenuitem* transport_menuitem_construct (GType object_type, PlayerController* parent);
-void transport_menuitem_change_play_state (TransportMenuitem* self, gint state);
+void transport_menuitem_change_play_state (TransportMenuitem* self, TransportMenuitemstate update);
GeeHashSet* transport_menuitem_attributes_format (void);
GType metadata_menuitem_get_type (void) G_GNUC_CONST;
extern char* metadata_menuitem_album_art_cache_dir;
@@ -352,6 +360,7 @@ GeeHashSet* scrub_menuitem_attributes_format (void);
GType title_menuitem_get_type (void) G_GNUC_CONST;
TitleMenuitem* title_menuitem_new (PlayerController* parent);
TitleMenuitem* title_menuitem_construct (GType object_type, PlayerController* parent);
+void title_menuitem_toggle_active_triangle (TitleMenuitem* self, gboolean update);
GeeHashSet* title_menuitem_attributes_format (void);
GType mpris2_controller_get_type (void) G_GNUC_CONST;
GType player_controller_widget_order_get_type (void) G_GNUC_CONST;
diff --git a/src/play-button.c b/src/play-button.c
index ccc23cb..0c934e5 100644
--- a/src/play-button.c
+++ b/src/play-button.c
@@ -388,19 +388,20 @@ determine_button_event(GtkWidget* button, GdkEventButton* event)
g_debug("event y coordinate = %f", event->y);
PlayButtonEvent button_event = TRANSPORT_NADA;
// For now very simple rectangular collision detection
- if(event->x > 55 && event->x < 95
+ if(event->x > 67 && event->x < 112
&& event->y > 12 && event->y < 40){
button_event = TRANSPORT_PREVIOUS;
}
- else if(event->x > 99 && event->x < 136
+ else if(event->x > 111 && event->x < 153
&& event->y > 5 && event->y < 47){
button_event = TRANSPORT_PLAY_PAUSE;
}
- else if(event->x > 137 && event->x < 179
+ else if(event->x > 152 && event->x < 197
&& event->y > 12 && event->y < 40){
button_event = TRANSPORT_NEXT;
}
return button_event;
+
}
void
@@ -730,8 +731,8 @@ draw (GtkWidget* button, cairo_t *cr)
cairo_surface_t* surf = NULL;
cairo_t* cr_surf = NULL;
- double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f};
- double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f};
+ //double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f};
+ //double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f};
double MIDDLE_START[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f};
double MIDDLE_END[] = {94.0f / 255.0f,93.0f / 255.0f, 90.0f / 255.0f,1.0f};
double OUTER_START[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f};
diff --git a/src/player-controller.c b/src/player-controller.c
index 51eafe8..b7be2a0 100644
--- a/src/player-controller.c
+++ b/src/player-controller.c
@@ -101,6 +101,8 @@ typedef struct _MetadataMenuitemClass MetadataMenuitemClass;
typedef struct _TransportMenuitem TransportMenuitem;
typedef struct _TransportMenuitemClass TransportMenuitemClass;
+#define TRANSPORT_MENUITEM_TYPE_STATE (transport_menuitem_state_get_type ())
+
struct _PlayerController {
GObject parent_instance;
PlayerControllerPrivate * priv;
@@ -135,6 +137,11 @@ typedef enum {
PLAYER_CONTROLLER_STATE_DISCONNECTED
} PlayerControllerstate;
+typedef enum {
+ TRANSPORT_MENUITEM_STATE_PLAYING,
+ TRANSPORT_MENUITEM_STATE_PAUSED
+} TransportMenuitemstate;
+
static gpointer player_controller_parent_class = NULL;
@@ -172,12 +179,13 @@ void player_controller_hibernate (PlayerController* self);
void player_item_reset (PlayerItem* self, GeeHashSet* attrs);
GeeHashSet* transport_menuitem_attributes_format (void);
GeeHashSet* metadata_menuitem_attributes_format (void);
+GType title_menuitem_get_type (void) G_GNUC_CONST;
+void title_menuitem_toggle_active_triangle (TitleMenuitem* self, gboolean update);
gboolean player_item_populated (PlayerItem* self, GeeHashSet* attrs);
PlayerItem* player_item_new (const char* type);
PlayerItem* player_item_construct (GType object_type, const char* type);
TitleMenuitem* title_menuitem_new (PlayerController* parent);
TitleMenuitem* title_menuitem_construct (GType object_type, PlayerController* parent);
-GType title_menuitem_get_type (void) G_GNUC_CONST;
MetadataMenuitem* metadata_menuitem_new (void);
MetadataMenuitem* metadata_menuitem_construct (GType object_type);
GType metadata_menuitem_get_type (void) G_GNUC_CONST;
@@ -186,6 +194,8 @@ TransportMenuitem* transport_menuitem_construct (GType object_type, PlayerContro
GType transport_menuitem_get_type (void) G_GNUC_CONST;
gint player_controller_get_menu_offset (PlayerController* self);
gboolean mpris2_controller_connected (Mpris2Controller* self);
+GType transport_menuitem_state_get_type (void) G_GNUC_CONST;
+void transport_menuitem_change_play_state (TransportMenuitem* self, TransportMenuitemstate update);
void player_controller_set_app_info (PlayerController* self, GAppInfo* value);
static void player_controller_finalize (GObject* obj);
static void player_controller_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
@@ -345,6 +355,8 @@ void player_controller_hibernate (PlayerController* self) {
GeeHashSet* _tmp1_;
PlayerItem* _tmp2_;
GeeHashSet* _tmp3_;
+ PlayerItem* _tmp4_;
+ TitleMenuitem* title;
g_return_if_fail (self != NULL);
player_controller_update_state (self, PLAYER_CONTROLLER_STATE_OFFLINE);
player_item_reset (_tmp0_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TRANSPORT), _tmp1_ = transport_menuitem_attributes_format ());
@@ -353,6 +365,9 @@ void player_controller_hibernate (PlayerController* self) {
player_item_reset (_tmp2_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_METADATA), _tmp3_ = metadata_menuitem_attributes_format ());
_g_object_unref0 (_tmp3_);
_g_object_unref0 (_tmp2_);
+ title = (_tmp4_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TITLE), IS_TITLE_MENUITEM (_tmp4_) ? ((TitleMenuitem*) _tmp4_) : NULL);
+ title_menuitem_toggle_active_triangle (title, FALSE);
+ _g_object_unref0 (title);
}
@@ -467,7 +482,7 @@ static char* player_controller_format_client_name (const char* client_name) {
formatted = (_tmp2_ = g_strconcat (_tmp0_ = g_utf8_strup (client_name, (gssize) 1), _tmp1_ = string_slice (client_name, (glong) 1, g_utf8_strlen (client_name, -1)), NULL), _g_free0 (formatted), _tmp2_);
_g_free0 (_tmp1_);
_g_free0 (_tmp0_);
- g_debug ("player-controller.vala:163: PlayerController->format_client_name - : %" \
+ g_debug ("player-controller.vala:165: PlayerController->format_client_name - : %" \
"s", formatted);
}
result = formatted;
@@ -478,7 +493,17 @@ static char* player_controller_format_client_name (const char* client_name) {
void player_controller_determine_state (PlayerController* self) {
g_return_if_fail (self != NULL);
if (mpris2_controller_connected (self->mpris_bridge) == TRUE) {
+ PlayerItem* _tmp0_;
+ TitleMenuitem* title;
+ PlayerItem* _tmp1_;
+ TransportMenuitem* transport;
player_controller_update_state (self, PLAYER_CONTROLLER_STATE_CONNECTED);
+ title = (_tmp0_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TITLE), IS_TITLE_MENUITEM (_tmp0_) ? ((TitleMenuitem*) _tmp0_) : NULL);
+ title_menuitem_toggle_active_triangle (title, TRUE);
+ transport = (_tmp1_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TRANSPORT), IS_TRANSPORT_MENUITEM (_tmp1_) ? ((TransportMenuitem*) _tmp1_) : NULL);
+ transport_menuitem_change_play_state (transport, TRANSPORT_MENUITEM_STATE_PAUSED);
+ _g_object_unref0 (transport);
+ _g_object_unref0 (title);
} else {
player_controller_update_state (self, PLAYER_CONTROLLER_STATE_DISCONNECTED);
}
diff --git a/src/player-controller.vala b/src/player-controller.vala
index 4d9f054..f5ec205 100644
--- a/src/player-controller.vala
+++ b/src/player-controller.vala
@@ -116,6 +116,8 @@ public class PlayerController : GLib.Object
update_state(PlayerController.state.OFFLINE);
this.custom_items[widget_order.TRANSPORT].reset(TransportMenuitem.attributes_format());
this.custom_items[widget_order.METADATA].reset(MetadataMenuitem.attributes_format());
+ TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem;
+ title.toggle_active_triangle(false);
}
public void update_layout()
@@ -172,6 +174,10 @@ public class PlayerController : GLib.Object
{
if(this.mpris_bridge.connected() == true){
this.update_state(state.CONNECTED);
+ TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem;
+ title.toggle_active_triangle(true);
+ TransportMenuitem transport = this.custom_items[widget_order.TRANSPORT] as TransportMenuitem;
+ transport.change_play_state(TransportMenuitem.state.PAUSED);
}
else{
this.update_state(state.DISCONNECTED);
diff --git a/src/title-menu-item.c b/src/title-menu-item.c
index 56621ac..f66a8f8 100644
--- a/src/title-menu-item.c
+++ b/src/title-menu-item.c
@@ -134,6 +134,7 @@ GType mpris2_controller_get_type (void) G_GNUC_CONST;
GType player_controller_state_get_type (void) G_GNUC_CONST;
void player_controller_instantiate (PlayerController* self);
void mpris2_controller_expose (Mpris2Controller* self);
+void title_menuitem_toggle_active_triangle (TitleMenuitem* self, gboolean update);
GeeHashSet* title_menuitem_attributes_format (void);
@@ -143,6 +144,7 @@ TitleMenuitem* title_menuitem_construct (GType object_type, PlayerController* pa
g_return_val_if_fail (parent != NULL, NULL);
self = (TitleMenuitem*) g_object_new (object_type, "item-type", DBUSMENU_TITLE_MENUITEM_TYPE, "owner", parent, NULL);
dbusmenu_menuitem_property_set ((DbusmenuMenuitem*) self, DBUSMENU_TITLE_MENUITEM_NAME, player_controller_get_name (parent));
+ dbusmenu_menuitem_property_set_bool ((DbusmenuMenuitem*) self, DBUSMENU_TITLE_MENUITEM_RUNNING, FALSE);
return self;
}
@@ -166,6 +168,12 @@ static void title_menuitem_real_handle_event (DbusmenuMenuitem* base, const char
}
+void title_menuitem_toggle_active_triangle (TitleMenuitem* self, gboolean update) {
+ g_return_if_fail (self != NULL);
+ dbusmenu_menuitem_property_set_bool ((DbusmenuMenuitem*) self, DBUSMENU_TITLE_MENUITEM_RUNNING, update);
+}
+
+
GeeHashSet* title_menuitem_attributes_format (void) {
GeeHashSet* result = NULL;
GeeHashSet* attrs;
diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala
index ec1cc62..bb3d103 100644
--- a/src/title-menu-item.vala
+++ b/src/title-menu-item.vala
@@ -27,6 +27,7 @@ public class TitleMenuitem : PlayerItem
{
Object(item_type: MENUITEM_TYPE, owner: parent);
this.property_set(MENUITEM_NAME, parent.name);
+ this.property_set_bool(MENUITEM_RUNNING, false);
}
public override void handle_event(string name, GLib.Value input_value, uint timestamp)
@@ -39,7 +40,11 @@ public class TitleMenuitem : PlayerItem
this.owner.mpris_bridge.expose();
}
}
-
+
+ public void toggle_active_triangle(bool update)
+ {
+ this.property_set_bool(MENUITEM_RUNNING, update);
+ }
public static HashSet<string> attributes_format()
{
diff --git a/src/title-widget.c b/src/title-widget.c
index e9f34d6..1146818 100644
--- a/src/title-widget.c
+++ b/src/title-widget.c
@@ -32,10 +32,7 @@ typedef struct _TitleWidgetPrivate TitleWidgetPrivate;
struct _TitleWidgetPrivate
{
- GtkWidget* hbox;
- GtkWidget* name;
- GtkWidget* player_icon;
- DbusmenuMenuitem* twin_item;
+ DbusmenuMenuitem* twin_item;
};
#define TITLE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TITLE_WIDGET_TYPE, TitleWidgetPrivate))
@@ -54,10 +51,12 @@ static gboolean title_widget_button_press_event (GtkWidget *menuitem,
static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property,
GValue* value, gpointer userdata);
static void title_widget_set_twin_item( TitleWidget* self,
- DbusmenuMenuitem* twin_item);
-static void title_widget_style_name_text(TitleWidget* self);
+ DbusmenuMenuitem* twin_item);
+static gboolean title_widget_triangle_draw_cb (GtkWidget *widget,
+ GdkEventExpose *event,
+ gpointer data);
-G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_MENU_ITEM);
+G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_IMAGE_MENU_ITEM);
@@ -73,7 +72,6 @@ title_widget_class_init (TitleWidgetClass *klass)
gobject_class->dispose = title_widget_dispose;
gobject_class->finalize = title_widget_finalize;
-
}
static void
@@ -81,15 +79,22 @@ title_widget_init (TitleWidget *self)
{
g_debug("TitleWidget::title_widget_init");
- TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self);
+ gint padding = 0;
+ gtk_widget_style_get(GTK_WIDGET(self), "horizontal-padding", &padding, NULL);
+
+ gint width, height;
+ gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
- GtkWidget *hbox;
+ GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU);
- hbox = gtk_hbox_new(FALSE, 0);
- priv->hbox = hbox;
+ gtk_widget_set_size_request(icon, width
+ + 5 /* ref triangle is 5x9 pixels */
+ + 1 /* padding */,
+ height);
+ gtk_misc_set_alignment(GTK_MISC(icon), 0.5 /* right aligned */, 0);
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon));
+ gtk_widget_show(icon);
- priv->player_icon = indicator_image_helper("sound_icon");
- gtk_box_pack_start(GTK_BOX (priv->hbox), priv->player_icon, FALSE, FALSE, 0);
}
static void
@@ -127,11 +132,10 @@ title_widget_property_update(DbusmenuMenuitem* item, gchar* property,
{
g_return_if_fail (IS_TITLE_WIDGET (userdata));
TitleWidget* mitem = TITLE_WIDGET(userdata);
- TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(mitem);
-
- if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){
- gtk_label_set_text(GTK_LABEL(priv->name), g_value_get_string(value));
- title_widget_style_name_text(mitem);
+
+ if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){
+ gtk_menu_item_set_label (GTK_MENU_ITEM(mitem),
+ g_value_get_string(value));
}
}
@@ -139,33 +143,72 @@ static void
title_widget_set_twin_item(TitleWidget* self,
DbusmenuMenuitem* twin_item)
{
- TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self);
- priv->twin_item = twin_item;
- g_signal_connect(G_OBJECT(twin_item), "property-changed",
- G_CALLBACK(title_widget_property_update), self);
- priv->name = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item,
- DBUSMENU_TITLE_MENUITEM_NAME));
- gtk_misc_set_padding(GTK_MISC(priv->name), 10, 0);
- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->name, FALSE, FALSE, 0);
-
- title_widget_style_name_text(self);
-
- gtk_widget_show_all (priv->hbox);
- gtk_container_add (GTK_CONTAINER (self), priv->hbox);
+ TitleWidgetPrivate *priv = TITLE_WIDGET_GET_PRIVATE(self);
+
+ priv->twin_item = twin_item;
+
+ g_signal_connect (G_OBJECT (twin_item),
+ "property-changed",
+ G_CALLBACK (title_widget_property_update),
+ self);
+ g_signal_connect_after (G_OBJECT (self),
+ "expose_event",
+ G_CALLBACK (title_widget_triangle_draw_cb),
+ twin_item);
+
+ gtk_menu_item_set_label (GTK_MENU_ITEM(self),
+ dbusmenu_menuitem_property_get(priv->twin_item,
+ DBUSMENU_TITLE_MENUITEM_NAME));
+
}
-static void
-title_widget_style_name_text(TitleWidget* self)
+static gboolean
+title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
- TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self);
+ GtkStyle *style;
+ cairo_t *cr;
+ int x, y, arrow_width, arrow_height;
+
+ if (!GTK_IS_WIDGET (widget)) return FALSE;
+ if (!DBUSMENU_IS_MENUITEM (data)) return FALSE;
+
+ /* render the triangle indicator only if the application is running */
+ if (! dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM(data),
+ DBUSMENU_TITLE_MENUITEM_RUNNING)){
+ return FALSE;
+ }
+
+ /* get style */
+ style = gtk_widget_get_style (widget);
+
+ /* set arrow position / dimensions */
+ arrow_width = 5; /* the pixel-based reference triangle is 5x9 */
+ arrow_height = 9;
+ x = widget->allocation.x;
+ y = widget->allocation.y + widget->allocation.height/2.0 - (double)arrow_height/2.0;
+
+ /* initialize cairo drawing area */
+ cr = (cairo_t*) gdk_cairo_create (widget->window);
+
+ /* set line width */
+ cairo_set_line_width (cr, 1.0);
+
+ /* cairo drawing code */
+ cairo_move_to (cr, x, y);
+ cairo_line_to (cr, x, y + arrow_height);
+ cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0);
+ cairo_close_path (cr);
+ cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
+ style->fg[gtk_widget_get_state(widget)].blue/65535.0);
+ cairo_fill (cr);
+
+ /* remember to destroy cairo context to avoid leaks */
+ cairo_destroy (cr);
- char* markup;
- markup = g_markup_printf_escaped ("<span size=\"medium\">%s</span>",
- gtk_label_get_text(GTK_LABEL(priv->name)));
- gtk_label_set_markup (GTK_LABEL (priv->name), markup);
- g_free(markup);
+ return FALSE;
}
-
+
/**
* transport_new:
* @returns: a new #TitleWidget.
@@ -173,8 +216,11 @@ title_widget_style_name_text(TitleWidget* self)
GtkWidget*
title_widget_new(DbusmenuMenuitem *item)
{
- GtkWidget* widget = g_object_new(TITLE_WIDGET_TYPE, NULL);
+ GtkWidget* widget = g_object_new (TITLE_WIDGET_TYPE,
+ NULL);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (widget), TRUE);
title_widget_set_twin_item((TitleWidget*)widget, item);
+
return widget;
}
diff --git a/src/title-widget.h b/src/title-widget.h
index fc8f169..574a2b1 100644
--- a/src/title-widget.h
+++ b/src/title-widget.h
@@ -19,7 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef __TITLE_WIDGET_H__
#define __TITLE_WIDGET_H__
-#include <gtk/gtkmenuitem.h>
+#include <gtk/gtkimagemenuitem.h>
#include <libdbusmenu-gtk/menuitem.h>
G_BEGIN_DECLS
@@ -35,11 +35,11 @@ typedef struct _TitleWidget TitleWidget;
typedef struct _TitleWidgetClass TitleWidgetClass;
struct _TitleWidgetClass {
- GtkMenuItemClass parent_class;
+ GtkImageMenuItemClass parent_class;
};
struct _TitleWidget {
- GtkMenuItem parent;
+ GtkImageMenuItem parent;
};
GType title_widget_get_type (void);
diff --git a/src/transport-menu-item.c b/src/transport-menu-item.c
index ff00f5f..0181bd3 100644
--- a/src/transport-menu-item.c
+++ b/src/transport-menu-item.c
@@ -56,6 +56,8 @@ typedef struct _TransportMenuitemPrivate TransportMenuitemPrivate;
#define TRANSPORT_MENUITEM_TYPE_ACTION (transport_menuitem_action_get_type ())
+#define TRANSPORT_MENUITEM_TYPE_STATE (transport_menuitem_state_get_type ())
+
#define TYPE_PLAYER_CONTROLLER (player_controller_get_type ())
#define PLAYER_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLAYER_CONTROLLER, PlayerController))
#define PLAYER_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLAYER_CONTROLLER, PlayerControllerClass))
@@ -103,6 +105,11 @@ typedef enum {
TRANSPORT_MENUITEM_ACTION_NEXT
} TransportMenuitemaction;
+typedef enum {
+ TRANSPORT_MENUITEM_STATE_PLAYING,
+ TRANSPORT_MENUITEM_STATE_PAUSED
+} TransportMenuitemstate;
+
struct _PlayerController {
GObject parent_instance;
PlayerControllerPrivate * priv;
@@ -124,10 +131,11 @@ enum {
TRANSPORT_MENUITEM_DUMMY_PROPERTY
};
GType transport_menuitem_action_get_type (void) G_GNUC_CONST;
+GType transport_menuitem_state_get_type (void) G_GNUC_CONST;
GType player_controller_get_type (void) G_GNUC_CONST;
TransportMenuitem* transport_menuitem_new (PlayerController* parent);
TransportMenuitem* transport_menuitem_construct (GType object_type, PlayerController* parent);
-void transport_menuitem_change_play_state (TransportMenuitem* self, gint state);
+void transport_menuitem_change_play_state (TransportMenuitem* self, TransportMenuitemstate update);
static void transport_menuitem_real_handle_event (DbusmenuMenuitem* base, const char* name, GValue* input_value, guint timestamp);
PlayerController* player_item_get_owner (PlayerItem* self);
const char* player_controller_get_name (PlayerController* self);
@@ -149,6 +157,18 @@ GType transport_menuitem_action_get_type (void) {
}
+GType transport_menuitem_state_get_type (void) {
+ static volatile gsize transport_menuitem_state_type_id__volatile = 0;
+ if (g_once_init_enter (&transport_menuitem_state_type_id__volatile)) {
+ static const GEnumValue values[] = {{TRANSPORT_MENUITEM_STATE_PLAYING, "TRANSPORT_MENUITEM_STATE_PLAYING", "playing"}, {TRANSPORT_MENUITEM_STATE_PAUSED, "TRANSPORT_MENUITEM_STATE_PAUSED", "paused"}, {0, NULL, NULL}};
+ GType transport_menuitem_state_type_id;
+ transport_menuitem_state_type_id = g_enum_register_static ("TransportMenuitemstate", values);
+ g_once_init_leave (&transport_menuitem_state_type_id__volatile, transport_menuitem_state_type_id);
+ }
+ return transport_menuitem_state_type_id__volatile;
+}
+
+
TransportMenuitem* transport_menuitem_construct (GType object_type, PlayerController* parent) {
TransportMenuitem * self;
g_return_val_if_fail (parent != NULL, NULL);
@@ -163,9 +183,9 @@ TransportMenuitem* transport_menuitem_new (PlayerController* parent) {
}
-void transport_menuitem_change_play_state (TransportMenuitem* self, gint state) {
+void transport_menuitem_change_play_state (TransportMenuitem* self, TransportMenuitemstate update) {
g_return_if_fail (self != NULL);
- dbusmenu_menuitem_property_set_int ((DbusmenuMenuitem*) self, DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE, state);
+ dbusmenu_menuitem_property_set_int ((DbusmenuMenuitem*) self, DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE, (gint) update);
}
@@ -176,9 +196,9 @@ static void transport_menuitem_real_handle_event (DbusmenuMenuitem* base, const
self = (TransportMenuitem*) base;
g_return_if_fail (name != NULL);
input = g_value_get_int (input_value);
- g_debug ("transport-menu-item.vala:46: handle_event with value %s", _tmp0_ = g_strdup_printf ("%i", input));
+ g_debug ("transport-menu-item.vala:51: handle_event with value %s", _tmp0_ = g_strdup_printf ("%i", input));
_g_free0 (_tmp0_);
- g_debug ("transport-menu-item.vala:47: transport owner name = %s", player_controller_get_name (player_item_get_owner ((PlayerItem*) self)));
+ g_debug ("transport-menu-item.vala:52: transport owner name = %s", player_controller_get_name (player_item_get_owner ((PlayerItem*) self)));
mpris2_controller_transport_update (player_item_get_owner ((PlayerItem*) self)->mpris_bridge, (TransportMenuitemaction) input);
}
diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala
index 8bdd2c8..7faadb5 100644
--- a/src/transport-menu-item.vala
+++ b/src/transport-menu-item.vala
@@ -28,6 +28,11 @@ public class TransportMenuitem : PlayerItem
PLAY_PAUSE,
NEXT
}
+
+ public enum state{
+ PLAYING,
+ PAUSED
+ }
public TransportMenuitem(PlayerController parent)
{
@@ -35,9 +40,9 @@ public class TransportMenuitem : PlayerItem
this.property_set_int(MENUITEM_PLAY_STATE, 1);
}
- public void change_play_state(int state)
+ public void change_play_state(state update)
{
- this.property_set_int(MENUITEM_PLAY_STATE, state);
+ this.property_set_int(MENUITEM_PLAY_STATE, update);
}
public override void handle_event(string name, GLib.Value input_value, uint timestamp)
@@ -54,4 +59,6 @@ public class TransportMenuitem : PlayerItem
attrs.add(MENUITEM_PLAY_STATE);
return attrs;
}
+
+
} \ No newline at end of file