chiark / gitweb /
more systematic elimination of feedback from the gui
authorRichard Kettlewell <rjk@greenend.org.uk>
Fri, 16 Nov 2007 13:24:49 +0000 (13:24 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Fri, 16 Nov 2007 13:24:49 +0000 (13:24 +0000)
disobedience/control.c
disobedience/disobedience.c
disobedience/disobedience.h
disobedience/log.c

index ecdc1a6bb9f6ba8da2dfd0c8e4637511b662a3f0..e1f44f28fcea9102aee9d42b1940575d5b154df5 100644 (file)
@@ -67,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
  *
@@ -303,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
@@ -399,14 +399,16 @@ 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,
@@ -414,6 +416,8 @@ static void toggled_menu(GtkCheckMenuItem *menuitem,
   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. */
@@ -431,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;
index 54b6be8ac166fec3c19c751f75b49662f5ccef24..d6b346d05cdf9c1672c035c1946d080ef800b599 100644 (file)
@@ -350,20 +350,24 @@ static gboolean maybe_send_nop(gpointer attribute((unused)) data) {
 static void got_rtp_address(void attribute((unused)) *v,
                             int attribute((unused)) nvec,
                             char attribute((unused)) **vec) {
+  ++suppress_actions;
   rtp_address_in_flight = 0;
   rtp_supported = 1;
   rtp_is_running = rtp_running();
   control_monitor(0);
+  --suppress_actions;
 }
 
 /** @brief Called when a rtp-address command fails */
 static void no_rtp_address(struct callbackdata attribute((unused)) *cbd,
                            int attribute((unused)) code,
                            const char attribute((unused)) *msg) {
+  ++suppress_actions;
   rtp_address_in_flight = 0;
   rtp_supported = 0;
   rtp_is_running = 0;
   control_monitor(0);
+  --suppress_actions;
 }
 
 /** @brief Called to check whether RTP play is available */
@@ -487,6 +491,7 @@ int main(int argc, char **argv) {
   disorder_eclient_log(logclient, &log_callbacks, 0);
   /* See if RTP play supported */
   check_rtp_address();
+  suppress_actions = 0;
   D(("enter main loop"));
   MTAG("misc");
   g_main_loop_run(mainloop);
index ea5d095257899dc867dbf706cfb371ac9e2dae51..999ef3166df136f600cabd66b848609a1567a296 100644 (file)
@@ -194,6 +194,8 @@ void volume_update(void);
 
 void control_monitor(void *u);
 
+extern int suppress_actions;
+
 /* Queue/Recent/Added */
 
 GtkWidget *queue_widget(void);
index af386431f0fb66b2ff1af6a049f608aa5e43f994..b0aaace133ef1795dff00ed9ab1df1df64a9f324 100644 (file)
@@ -83,10 +83,12 @@ static struct monitor *monitors;
 
 /** @brief Update everything */
 void all_update(void) {
+  ++suppress_actions;
   queue_update();
   recent_update();
   volume_update();
   added_update();
+  --suppress_actions;
 }
 
 /** @brief Called when the client connects
@@ -167,7 +169,8 @@ static void log_state(void attribute((unused)) *v,
   const struct monitor *m;
   unsigned long changes = state ^ last_state;
   static int first = 1;
-  
+
+  ++suppress_actions;
   if(first) {
     changes = -1UL;
     first = 0;
@@ -182,6 +185,7 @@ static void log_state(void attribute((unused)) *v,
     if(changes & m->mask)
       m->callback(m->u);
   }
+  --suppress_actions;
 }
 
 /** @brief Called when volume changes */
@@ -190,7 +194,9 @@ static void log_volume(void attribute((unused)) *v,
   if(!rtp_supported && (volume_l != l || volume_r != r)) {
     volume_l = l;
     volume_r = r;
+    ++suppress_actions;
     volume_update();
+    --suppress_actions;
   }
 }