示例#1
0
/* Called when someone clicks on the guest session item. */
static void
activate_guest_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data)
{
	GError * error = NULL;

	lock_if_possible();

	if (dbusmenu_menuitem_property_get_bool(mi, USER_ITEM_PROP_LOGGED_IN)) {
		if (users_service_dbus_activate_guest_session(USERS_SERVICE_DBUS(user_data))) {
			return;
		}
		g_warning("Unable to activate guest session, falling back to command line activation.");
	}

	if (!g_spawn_command_line_async(GUEST_SESSION_LAUNCHER " --no-lock", &error)) {
		g_warning("Unable to start guest session: %s", error->message);
		g_error_free(error);
	}

	return;
}
/* Draws a triangle on the left, using fg[STATE_TYPE] color. */
static gboolean
application_triangle_draw_cb (GtkWidget *widget, cairo_t *ctx, gpointer data)
{
	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), APPLICATION_MENUITEM_PROP_RUNNING))
		return FALSE;;

	arrow_width = 5; /* the pixel-based reference triangle is 5x9 */
	arrow_height = 9;
	
	/* get style + arrow position */
	double red, green, blue;
	GtkStyleContext *style = gtk_widget_get_style_context (widget);
	GdkRGBA color;
	gtk_style_context_get_color (style, gtk_widget_get_state(widget), &color);
	red = color.red;
	green = color.green;
	blue = color.blue;
	x = 0;  // the context is already translated so that (0;0) is the top-left corner of the widget.
	y = gtk_widget_get_allocated_height (widget)/2.0 - (double)arrow_height/2.0;

	cairo_set_line_width (ctx, 1.0);

	/* cairo drawing code */
	cairo_move_to (ctx, x, y);
	cairo_line_to (ctx, x, y + arrow_height);
	cairo_line_to (ctx, x + arrow_width, y + (double)arrow_height/2.0);
	cairo_close_path (ctx);
	cairo_set_source_rgb (ctx, red, green, blue);
	cairo_fill (ctx);

	return FALSE;
}
/* Builds a menu item representing a running application in the
   messaging menu */
static gboolean
new_application_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
{
	gchar *cName = g_strdup (dbusmenu_menuitem_property_get(newitem, APPLICATION_MENUITEM_PROP_NAME));
	const gchar *sIconName = dbusmenu_menuitem_property_get (newitem, APPLICATION_MENUITEM_PROP_ICON);

	cd_debug ("%s (\"%s\")", __func__, cName);

#ifdef FORCE_REMOVE_DOUBLE_ENTRIES
#if (INDICATOR_OLD_NAMES == 0)
	if (newitem == NULL || !dbusmenu_menuitem_property_get_bool(newitem, DBUSMENU_MENUITEM_PROP_VISIBLE)
		#if INDICATOR_MESSAGES_HAS_LOZENGE == 1
		&& sIconName != NULL && *sIconName != '\0' // these menu 
		#endif
		)
	{
		dbusmenu_menuitem_child_delete (parent, newitem);
		cd_debug ("Not visible: %s", cName);
		g_free (cName);
		return TRUE;
	}
#endif
#endif

	GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_image_menu_item_new());

	gint padding = 4;
	gtk_widget_style_get(GTK_WIDGET(gmi), "toggle-spacing", &padding, NULL);

	GtkWidget * hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, padding);

	// Added for Cairo-Dock
	#if INDICATOR_MESSAGES_HAS_LOZENGE == 1 // we add a left margin
	if (! dbusmenu_menuitem_property_get_bool(newitem, DBUSMENU_MENUITEM_PROP_VISIBLE)
		&& (sIconName == NULL || *sIconName == '\0'))
	{
		gint width, height;
		gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
		gtk_widget_set_size_request(GTK_WIDGET (gmi), -1, height + 4);
		gtk_widget_set_margin_left (hbox, width + padding);
	}
	#endif
	// end

	GtkWidget * icon = gtk_image_new_from_icon_name(sIconName, GTK_ICON_SIZE_MENU);
	gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5);
	gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);

	/* Application name in a label */
	GtkWidget * label = gtk_label_new(cName);
	gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
	gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);

	gtk_container_add(GTK_CONTAINER(gmi), hbox);
	gtk_widget_show_all (GTK_WIDGET (gmi));

	/* Attach some of the standard GTK stuff */
	dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent);

	/* Make sure we can handle the label changing */
	g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(application_prop_change_cb), label);
	g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(application_icon_change_cb), icon);
	g_signal_connect_after(G_OBJECT (gmi), "draw", G_CALLBACK (application_triangle_draw_cb), newitem);

	g_free (cName);

	return TRUE;
}