Esempio n. 1
0
static void
impl_activate(PeasActivatable *activatable)
{
	XmrIndicatorPlugin *plugin;
	XmrWindow *window = NULL;
	XmrPlayer *player;

	plugin = XMR_INDICATOR_PLUGIN(activatable);
	g_object_get(plugin, "object", &window, NULL);

	if (window)
	{
		plugin->window = window;
		if (!plugin->indicator)
		{
#if HAVE_APP_INDICATOR
			gchar *icon_path;
			plugin->indicator = xmr_app_indicator_new(plugin->popup_menu);
			
			icon_path = g_build_filename(xmr_app_dir(), "icons", NULL);
			if (g_file_test(icon_path, G_FILE_TEST_EXISTS))
				app_indicator_set_icon_theme_path(APP_INDICATOR(plugin->indicator), icon_path);
			g_free(icon_path);
#else
			plugin->indicator = xmr_tray_icon_new(GTK_WIDGET(window), plugin->popup_menu);
#endif
		}
		g_signal_connect(window, "delete-event",
				G_CALLBACK(on_xmr_window_delete), plugin);

		g_signal_connect(window, "track-changed",
				G_CALLBACK(track_changed), plugin);
		
		g_object_get(window, "player", &player, NULL);
		if (player)
		{
			g_signal_connect(player, "state-changed", G_CALLBACK(player_state_changed), plugin);
			g_object_unref(player);
		}
	}

	plugin->hide_on_exit  = g_settings_get_boolean(plugin->settings, "hide-on-exit");
	g_signal_connect(plugin->settings,
				"changed",
				G_CALLBACK(on_settings_changed), plugin);

	if (xmr_window_playing(plugin->window)){
		gtk_widget_hide(plugin->menu_item_play);
	} else {
		gtk_widget_hide(plugin->menu_item_pause);
	}
}
Esempio n. 2
0
static GdkFilterReturn
filter_mmkeys(GdkXEvent *xevent,
			  GdkEvent *event,
			  gpointer data)
{
	XEvent *xev;
	XKeyEvent *key;
	Display *display;
	XmrWindow *window;
	
	GdkFilterReturn retv = GDK_FILTER_CONTINUE;

	xev = (XEvent *)xevent;

	if (xev->type != KeyPress)
		return GDK_FILTER_CONTINUE;

	key = (XKeyEvent *)xevent;

	window = (XmrWindow *)data;
	display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());

	if (XKeysymToKeycode(display, XF86XK_AudioPlay) == key->keycode ||
		XKeysymToKeycode(display, XF86XK_AudioPause) == key->keycode)
	{
		if (xmr_window_playing(window))
			xmr_window_pause(window);
		else
			xmr_window_play(window);
		retv = GDK_FILTER_REMOVE;
	}
	else if (XKeysymToKeycode (display, XF86XK_AudioStop) == key->keycode)
	{
		xmr_window_pause(window);
		retv = GDK_FILTER_REMOVE;
	}
	else if (XKeysymToKeycode (display, XF86XK_AudioNext) == key->keycode)
	{
		xmr_window_play_next(window);
		retv = GDK_FILTER_REMOVE;
	}
	
	return retv;
}
Esempio n. 3
0
static void
media_player_key_pressed(GDBusProxy *proxy,
			  const gchar *sender,
			  const gchar *signal,
			  GVariant *parameters,
			  XmrMMKeysPlugin *plugin)
{
	gchar *key;
	gchar *application;

	g_variant_get(parameters, "(ss)", &application, &key);

	if (g_strcmp0(application, PACKAGE))
	{
		xmr_debug("got media player key signal for unexpected application '%s'", application);
		return;
	}

	if (g_strcmp0(key, "Play") == 0 ||
		g_strcmp0(key, "Pause") == 0)
	{
		if (xmr_window_playing(plugin->window))
			xmr_window_pause(plugin->window);
		else
			xmr_window_play(plugin->window);
	}
	else if (g_strcmp0(key, "Stop") == 0)
	{
		xmr_window_pause(plugin->window);
	}
	else if (g_strcmp0(key, "Next") == 0)
	{
		xmr_window_play_next(plugin->window);
	}

	g_free(key);
	g_free(application);
}
Esempio n. 4
0
static void
handle_player_method_call(GDBusConnection *connection,
			const char *sender,
			const char *object_path,
			const char *interface_name,
			const char *method_name,
			GVariant *parameters,
			GDBusMethodInvocation *invocation,
			XmrMprisPlugin *plugin)

{
	if(g_strcmp0(object_path, MPRIS_OBJECT_NAME) != 0 ||
	    g_strcmp0(interface_name, MPRIS_PLAYER_INTERFACE) != 0)
	{
		g_dbus_method_invocation_return_error(invocation,
						       G_DBUS_ERROR,
						       G_DBUS_ERROR_NOT_SUPPORTED,
						       "Method %s.%s not supported",
						       interface_name,
						       method_name);
		return;
	}

	if (g_strcmp0(method_name, "Next") == 0)
	{
		xmr_window_play_next(plugin->window);
		handle_result(invocation, TRUE, NULL);
	}
	else if (g_strcmp0(method_name, "Pause") == 0)
	{
		if (xmr_window_playing(plugin->window))
		{
			xmr_window_pause(plugin->window);
			handle_result(invocation, TRUE, NULL);
		}
		else
		{
			handle_result(invocation, FALSE, NULL);
		}
	}
	else if (g_strcmp0 (method_name, "Play") == 0)
	{
		if (xmr_window_playing(plugin->window))
		{
			handle_result(invocation, FALSE, NULL);
		}
		else
		{
			xmr_window_play(plugin->window);
			handle_result(invocation, TRUE, NULL);
		}
	}
	else if (g_strcmp0(method_name, "PlayPause") == 0)
	{
		if (xmr_window_playing(plugin->window))
			xmr_window_pause(plugin->window);
		else
			xmr_window_play(plugin->window);

		handle_result(invocation, TRUE, NULL);
	}
	else
	{
		g_dbus_method_invocation_return_error(invocation,
					G_DBUS_ERROR,
					G_DBUS_ERROR_NOT_SUPPORTED,
					"Method %s.%s not supported",
					interface_name,
					method_name);
	}
}