4

My goal is to write a desktop gui application that will utilize these commands found in https://askubuntu.com/a/14083/18330

pacmd list-sinks to list name or index number of possible sinks

pacmd set-default-sink "SINKNAME" to set the default output sink

pacmd set-default-source "SOURCENAME" to set the default input

pacmd set-sink-volume index volume

pacmd set-source-volume index volume for volume control (0 = Mute, 65536 = 100%)

Then the application will have a tray icon that shows a list of sound devices that will be clickable to switch the sound device to that one. As they are clicked the sound volume will fade volume from 0 to the point the current system's volume (therefore I need access to the system volume as well.)

Unknowns:

  • How to programmatically add a tray icon in c++
  • How to make a drop down display when clicked on that tray icon and have it display items that are also clickable (much like how the mail icon displays Thunderbird)
  • How to bind the click events to a c++ function that will run (in order to switch to that sound device I will have a c++ function ready.)

I just need some guidance about identifying the desktop component that I'm trying to manipulate and where to find the API documentation for it.

Notes:

Logan
  • 431

1 Answers1

1

Check out libappindicator. It is responsible for putting the icon in the tray. The dropdown menu displayed by the indicator is a GtkMenu. The rest should be familiar if you worked with GTK+. Here is a minimal example.

#include <gtk/gtk.h>
#include <libappindicator/app-indicator.h>

static void do_something(GtkWidget *widget, gpointer data) {
  //...
}

int main (int argc, char **argv) {
  gtk_init(&argc, &argv);
  GtkWidget *menu = gtk_menu_new();
  GtkWidget *menuitem = gtk_menu_item_new_with_mnemonic("_This is a menu item");
  gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
  g_signal_connect(menuitem, "activate", G_CALLBACK(do_something), NULL);

  /* the second parameter is the icon displayed */
  AppIndicator* ind = app_indicator_new("test", "indicator-messages-new", 
                     APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
  app_indicator_set_menu(ind, GTK_MENU(menu));
  gtk_main();
}

You compile it with the following. You'll need libgtk2.0-dev and libappindicator-dev packages.

$ gcc test.c `pkg-config --cflags --libs gtk+-2.0 appindicator-0.1`

You'll figure out the rest. The easiest way is to check out other simple indicator applications. For example, see the indicator from this answer.

mkayaalp
  • 338