X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/ac6bf2bad50653d84388269a6629d121b8c37b8f..3149c1e2b844685497d87db1a031197527101766:/disobedience/control.c diff --git a/disobedience/control.c b/disobedience/control.c index 6542f82..e1f44f2 100644 --- a/disobedience/control.c +++ b/disobedience/control.c @@ -22,6 +22,7 @@ */ #include "disobedience.h" +#include "mixer.h" /* Forward declarations ---------------------------------------------------- */ @@ -46,6 +47,7 @@ static void update_rtp(const struct icon *); static void update_nortp(const struct icon *); static void clicked_icon(GtkButton *, gpointer); static void clicked_menu(GtkMenuItem *, gpointer userdata); +static void toggled_menu(GtkCheckMenuItem *, gpointer userdata); static int enable_rtp(disorder_eclient *c, disorder_eclient_no_response *completed, @@ -65,8 +67,8 @@ static gchar *format_balance(GtkScale *scale, gdouble value); /* Control bar ------------------------------------------------------------- */ -/** @brief Guard against feedback loop in volume control */ -static int suppress_set_volume; +/** @brief Guard against feedback */ +int suppress_actions = 1; /** @brief Definition of an icon * @@ -91,6 +93,9 @@ struct icon { disorder_eclient_no_response *completed, void *v); + /** @brief Flag */ + unsigned flags; + /** @brief Pointer to button */ GtkWidget *button; @@ -98,35 +103,104 @@ struct icon { GtkWidget *item; }; +/** @brief This is the active half of a pair */ +#define ICON_ACTIVE 0x0001 + +/** @brief This is the inactive half of a pair */ +#define ICON_INACTIVE 0x0002 + /** @brief Table of all icons */ static struct icon icons[] = { - { "pause.png", "Pause playing track", 0, - update_pause, - disorder_eclient_pause, 0, 0 }, - { "play.png", "Resume playing track", 0, - update_play, - disorder_eclient_resume, 0, 0 }, - { "cross.png", "Cancel playing track", "/Control/Scratch", - update_scratch, - disorder_eclient_scratch_playing, 0, 0 }, - { "random.png", "Enable random play", 0, - update_random_enable, - disorder_eclient_random_enable, 0, 0 }, - { "randomcross.png", "Disable random play", 0, - update_random_disable, - disorder_eclient_random_disable, 0, 0 }, - { "notes.png", "Enable play", 0, - update_enable, - disorder_eclient_enable, 0, 0 }, - { "notescross.png", "Disable play", 0, - update_disable, - disorder_eclient_disable, 0, 0 }, - { "speaker.png", "Play network stream", 0, - update_rtp, - enable_rtp, 0, 0 }, - { "speakercross.png", "Stop playing network stream", 0, - update_nortp, - disable_rtp, 0, 0 }, + { + "pause.png", /* icon */ + "Pause playing track", /* tip */ + "/Control/Playing", /* menuitem */ + update_pause, /* update */ + disorder_eclient_pause, /* action */ + ICON_ACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "play.png", /* icon */ + "Resume playing track", /* tip */ + "/Control/Playing", /* menuitem */ + update_play, /* update */ + disorder_eclient_resume, /* action */ + ICON_INACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "cross.png", /* icon */ + "Cancel playing track", /* tip */ + "/Control/Scratch", /* menuitem */ + update_scratch, /* update */ + disorder_eclient_scratch_playing, /* action */ + 0, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "random.png", /* icon */ + "Enable random play", /* tip */ + "/Control/Random play", /* menuitem */ + update_random_enable, /* update */ + disorder_eclient_random_enable, /* action */ + ICON_INACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "randomcross.png", /* icon */ + "Disable random play", /* tip */ + "/Control/Random play", /* menuitem */ + update_random_disable, /* update */ + disorder_eclient_random_disable, /* action */ + ICON_ACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "notes.png", /* icon */ + "Enable play", /* tip */ + 0, /* menuitem */ + update_enable, /* update */ + disorder_eclient_enable, /* action */ + ICON_INACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "notescross.png", /* icon */ + "Disable play", /* tip */ + 0, /* menuitem */ + update_disable, /* update */ + disorder_eclient_disable, /* action */ + ICON_ACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "speaker.png", /* icon */ + "Play network stream", /* tip */ + "/Control/Network player", /* menuitem */ + update_rtp, /* update */ + enable_rtp, /* action */ + ICON_INACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, + { + "speakercross.png", /* icon */ + "Stop playing network stream", /* tip */ + "/Control/Network player", /* menuitem */ + update_nortp, /* update */ + disable_rtp, /* action */ + ICON_ACTIVE, /* flags */ + 0, /* button */ + 0 /* item */ + }, }; /** @brief Count of icons */ @@ -147,8 +221,6 @@ void control_monitor(void attribute((unused)) *u) { /** @brief Create the control bar */ GtkWidget *control_widget(void) { GtkWidget *hbox = gtk_hbox_new(FALSE, 1), *vbox; - GtkWidget *content; - GdkPixbuf *pb; GtkWidget *v, *b; int n; @@ -157,16 +229,7 @@ GtkWidget *control_widget(void) { assert(mainmenufactory); /* ordering must be right */ for(n = 0; n < NICONS; ++n) { NW(button); - icons[n].button = gtk_button_new(); - if((pb = find_image(icons[n].icon))) { - NW(image); - content = gtk_image_new_from_pixbuf(pb); - } else { - NW(label); - content = gtk_label_new(icons[n].icon); - } - gtk_container_add(GTK_CONTAINER(icons[n].button), content); - gtk_tooltips_set_tip(tips, icons[n].button, icons[n].tip, ""); + icons[n].button = iconbutton(icons[n].icon, icons[n].tip); g_signal_connect(G_OBJECT(icons[n].button), "clicked", G_CALLBACK(clicked_icon), &icons[n]); /* pop the icon in a vbox so it doesn't get vertically stretch if there are @@ -178,8 +241,19 @@ GtkWidget *control_widget(void) { if(icons[n].menuitem) { icons[n].item = gtk_item_factory_get_widget(mainmenufactory, icons[n].menuitem); - g_signal_connect(G_OBJECT(icons[n].item), "activate", - G_CALLBACK(clicked_menu), &icons[n]); + switch(icons[n].flags & (ICON_ACTIVE|ICON_INACTIVE)) { + case ICON_ACTIVE: + g_signal_connect(G_OBJECT(icons[n].item), "toggled", + G_CALLBACK(toggled_menu), &icons[n]); + break; + case ICON_INACTIVE: + /* Don't connect two instances of the signal! */ + break; + default: + g_signal_connect(G_OBJECT(icons[n].item), "activate", + G_CALLBACK(clicked_menu), &icons[n]); + break; + } } } /* create the adjustments for the volume control */ @@ -195,6 +269,8 @@ GtkWidget *control_widget(void) { v = gtk_hscale_new(volume_adj); NW(hscale); b = gtk_hscale_new(balance_adj); + gtk_widget_set_style(v, tool_style); + gtk_widget_set_style(b, tool_style); gtk_scale_set_digits(GTK_SCALE(v), 10); gtk_scale_set_digits(GTK_SCALE(b), 10); gtk_widget_set_size_request(v, 192, -1); @@ -227,10 +303,10 @@ void volume_update(void) { D(("volume_update")); l = volume_l / 100.0; r = volume_r / 100.0; - ++suppress_set_volume; + ++suppress_actions; gtk_adjustment_set_value(volume_adj, volume(l, r) * goesupto); gtk_adjustment_set_value(balance_adj, balance(l, r)); - --suppress_set_volume; + --suppress_actions; } /** @brief Update the state of one of the control icons @@ -255,10 +331,13 @@ static void update_icon(const struct icon *icon, if(visible) gtk_widget_set_sensitive(icon->button, usable); if(icon->item) { - /* There's an associated menu item */ - (visible ? gtk_widget_show : gtk_widget_hide)(icon->item); - if(visible) - gtk_widget_set_sensitive(icon->item, usable); + /* There's an associated menu item. These are always visible, but may not + * be usable. */ + if((icon->flags & (ICON_ACTIVE|ICON_INACTIVE)) == ICON_ACTIVE) { + /* The active half of a pair */ + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(icon->item), visible); + } + gtk_widget_set_sensitive(icon->item, usable); } } @@ -320,14 +399,34 @@ static void clicked_icon(GtkButton attribute((unused)) *button, gpointer userdata) { const struct icon *icon = userdata; - icon->action(client, 0, 0); + if(!suppress_actions) + icon->action(client, 0, 0); } static void clicked_menu(GtkMenuItem attribute((unused)) *menuitem, gpointer userdata) { const struct icon *icon = userdata; - icon->action(client, 0, 0); + if(!suppress_actions) + icon->action(client, 0, 0); +} + +static void toggled_menu(GtkCheckMenuItem *menuitem, + gpointer userdata) { + const struct icon *icon = userdata; + size_t n; + + if(suppress_actions) + return; + /* This is a bit fiddlier than the others, we need to find the action for the + * new state. If the new state is active then we want the ICON_INACTIVE + * version and vica versa. */ + for(n = 0; n < NICONS; ++n) + if(icons[n].item == icon->item + && !!(icons[n].flags & ICON_INACTIVE) == !!menuitem->active) + break; + if(n < NICONS) + icons[n].action(client, 0, 0); } /** @brief Called when the volume has been adjusted */ @@ -336,7 +435,7 @@ static void volume_adjusted(GtkAdjustment attribute((unused)) *a, double v = gtk_adjustment_get_value(volume_adj) / goesupto; double b = gtk_adjustment_get_value(balance_adj); - if(suppress_set_volume) + if(suppress_actions) /* This is the result of an update from the server, not a change from the * user. Don't feedback! */ return; @@ -346,10 +445,15 @@ static void volume_adjusted(GtkAdjustment attribute((unused)) *a, b = nearbyint(5 * b) / 5; /* Set the volume. We don't want a reply, we'll get the actual new volume * from the log. */ - disorder_eclient_volume(client, 0, - nearbyint(left(v, b) * 100), - nearbyint(right(v, b) * 100), - 0); + if(rtp_supported) { + int l = nearbyint(left(v, b) * 100), r = nearbyint(right(v, b) * 100); + mixer_control(&l, &r, 1); + } else + /* We don't want a reply, we'll get the actual new volume from the log. */ + disorder_eclient_volume(client, 0, + nearbyint(left(v, b) * 100), + nearbyint(right(v, b) * 100), + 0); } /** @brief Formats the volume value */