From eacbe640fa7ffb8a99a04ebf21f94982c3679a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 30 Mar 2013 19:25:21 +0100 Subject: MenuItem: use GtkLaunchContext with proper event timeout to launch applications Also discards non-activation events --- src/Makefile.am | 1 + src/metadata-menu-item.vala | 9 ++++++--- src/mpris2-controller.vala | 2 +- src/player-controller.vala | 7 +++++-- src/sound-service.c | 2 +- src/transport-menu-item.vala | 5 ++++- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 5a36822..0a67a7c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -81,6 +81,7 @@ music_bridge_VALAFLAGS = \ --pkg config \ --pkg gio-2.0 \ --pkg gio-unix-2.0 \ + --pkg gdk-3.0 \ --pkg gdk-pixbuf-2.0 \ --pkg libxml-2.0 diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index b2dd752..bcd4378 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -168,13 +168,16 @@ public class MetadataMenuitem : PlayerItem public override void handle_event (string name, Variant input_value, uint timestamp) - { + { + if (name != Dbusmenu.MENUITEM_EVENT_ACTIVATED) + return; + if(this.owner.current_state == PlayerController.state.OFFLINE) { - this.owner.instantiate(); + this.owner.instantiate(timestamp); } else if(this.owner.current_state == PlayerController.state.CONNECTED){ - this.owner.mpris_bridge.expose(); + this.owner.mpris_bridge.expose(timestamp); } } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 2cc8d12..5015f80 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -208,7 +208,7 @@ public class Mpris2Controller : GLib.Object return (this.player != null && this.mpris2_root != null); } - public void expose() + public void expose(uint timestamp) { if(this.connected() == true){ this.mpris2_root.Raise.begin(); diff --git a/src/player-controller.vala b/src/player-controller.vala index fd66a8a..764efa5 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -98,11 +98,14 @@ public class PlayerController : GLib.Object There is a need to wait before the application is on DBus before attempting to access its mpris address Hence only when the it has registered with us via libindicate do we attempt to kick off mpris communication */ - public void instantiate() + public void instantiate(uint timestamp) { debug("instantiate in player controller for %s", this.app_info.get_name() ); + try{ - this.app_info.launch(null, null); + var context = Gdk.Display.get_default().get_app_launch_context(); + context.set_timestamp(timestamp); + this.app_info.launch(null, context); this.update_state(state.INSTANTIATING); } catch(GLib.Error error){ diff --git a/src/sound-service.c b/src/sound-service.c index 0170f81..66ef7b0 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -88,7 +88,7 @@ main (int argc, char ** argv) { gboolean greeter_mode; - g_type_init(); + gdk_init(&argc, &argv); textdomain (GETTEXT_PACKAGE); bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); setlocale (LC_ALL, ""); diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 4ec7dad..0af3118 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -70,6 +70,9 @@ public class TransportMenuitem : PlayerItem Variant input_value, uint timestamp) { + if (name != Dbusmenu.MENUITEM_EVENT_ACTIVATED) + return; + Variant v = input_value; if ( input_value.is_of_type (VariantType.VARIANT)){ v = input_value.get_variant(); @@ -82,7 +85,7 @@ public class TransportMenuitem : PlayerItem } else{ this.cached_action = (Transport.Action)input; - this.owner.instantiate(); + this.owner.instantiate(timestamp); this.property_set_int (MENUITEM_PLAY_STATE, (int)Transport.State.LAUNCHING); } } -- cgit v1.2.3