]> mj.ucw.cz Git - ursary.git/commitdiff
More MPD controls
authorMartin Mares <mj@ucw.cz>
Sun, 9 Nov 2014 23:17:18 +0000 (00:17 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 9 Nov 2014 23:37:27 +0000 (00:37 +0100)
ursaryd.c

index 3b1d051313cd4b6eeffe5fd3004e9d2f36708311..16e4066a2b2b886c35e8c864e7ae59c5e34d6b75 100644 (file)
--- a/ursaryd.c
+++ b/ursaryd.c
@@ -337,13 +337,40 @@ static void update_default_sink_from_button(int button, int on)
 
 /*** MPD controls ***/
 
+static bool mpd_flash_state;
+
+static void mpd_flash_timeout(struct main_timer *t)
+{
+  mpd_flash_state ^= 1;
+  noct_set_button(12, mpd_flash_state);
+  timer_add_rel(t, 500);
+}
+
+static struct main_timer mpd_flash_timer = {
+  .handler = mpd_flash_timeout,
+};
+
 static void update_mpd(void)
 {
   const char *state = mpd_get_player_state();
   if (!strcmp(state, "play"))
-    noct_set_button(12, 1);
+    {
+      noct_set_button(12, 1);
+      timer_del(&mpd_flash_timer);
+    }
+  else if (!strcmp(state, "pause"))
+    {
+      if (!timer_is_active(&mpd_flash_timer))
+       {
+         mpd_flash_state = 1;
+         mpd_flash_timeout(&mpd_flash_timer);
+       }
+    }
   else
-    noct_set_button(12, 0);
+    {
+      noct_set_button(12, 0);
+      timer_del(&mpd_flash_timer);
+    }
 }
 
 static void mpd_button_timeout(struct main_timer *t)
@@ -359,28 +386,36 @@ static void update_mpd_from_button(int button UNUSED, int on)
     .handler = mpd_button_timeout,
   };
 
+  const char *state = mpd_get_player_state();
+
   if (!on)
     {
-      timer_del(&mpd_button_timer);
+      if (timer_is_active(&mpd_button_timer))
+       {
+         timer_del(&mpd_button_timer);
+         if (!strcmp(state, "play"))
+           {
+             DBG("MPD pause");
+             mpd_pause(1);
+           }
+         else if (!strcmp(state, "pause"))
+           {
+             DBG("MPD resume");
+             mpd_pause(0);
+           }
+       }
       return;
     }
 
-  const char *state = mpd_get_player_state();
   if (!strcmp(state, "stop"))
     {
       DBG("MPD play");
       mpd_play();
     }
-  else if (!strcmp(state, "play"))
+  else
     {
-      DBG("MPD pause");
+      DBG("MPD starting button timer");
       timer_add_rel(&mpd_button_timer, 1000);
-      mpd_pause(1);
-    }
-  else if (!strcmp(state, "pause"))
-    {
-      DBG("MPD resume");
-      mpd_pause(0);
     }
 }