Lagrange [work/v1.9]

Player: Hide volume slider after 3 sec idle time

=> 3d723de1022d2fdeccb9bae6f934e6936445ef21

diff --git a/src/audio/player.c b/src/audio/player.c
index e0003168..77c23104 100644
--- a/src/audio/player.c
+++ b/src/audio/player.c
@@ -29,6 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 #include 
 #include 
 #include 
+#include 
 
 #if defined (LAGRANGE_ENABLE_MPG123)
 #  include 
@@ -443,6 +444,7 @@ struct Impl_Player {
     float             volume;
     int               flags;
     iInputBuf *       data;
+    uint32_t          lastInteraction;
     iDecoder *        decoder;
 };
 
@@ -695,12 +697,14 @@ iBool start_Player(iPlayer *d) {
     d->decoder = new_Decoder(d->data, &content);
     d->decoder->gain = d->volume;
     SDL_PauseAudioDevice(d->device, SDL_FALSE);
+    setNotIdle_Player(d);
     return iTrue;
 }
 
 void setPaused_Player(iPlayer *d, iBool isPaused) {
     if (isStarted_Player(d)) {
         SDL_PauseAudioDevice(d->device, isPaused ? SDL_TRUE : SDL_FALSE);
+        setNotIdle_Player(d);
     }
 }
 
@@ -720,10 +724,16 @@ void setVolume_Player(iPlayer *d, float volume) {
     if (d->decoder) {
         d->decoder->gain = d->volume;
     }
+    setNotIdle_Player(d);
 }
 
 void setFlags_Player(iPlayer *d, int flags, iBool set) {
     iChangeFlags(d->flags, flags, set);
+    setNotIdle_Player(d);
+}
+
+void setNotIdle_Player(iPlayer *d) {
+    d->lastInteraction = SDL_GetTicks();
 }
 
 int flags_Player(const iPlayer *d) {
@@ -760,6 +770,10 @@ float streamProgress_Player(const iPlayer *d) {
     return 0;
 }
 
+uint32_t idleTimeMs_Player(const iPlayer *d) {
+    return SDL_GetTicks() - d->lastInteraction;
+}
+
 iString *metadataLabel_Player(const iPlayer *d) {
     iString *meta = new_String();
     if (d->decoder) {
diff --git a/src/audio/player.h b/src/audio/player.h
index 58947ef4..82d95fd2 100644
--- a/src/audio/player.h
+++ b/src/audio/player.h
@@ -54,6 +54,7 @@ void    stop_Player             (iPlayer *);
 void    setPaused_Player        (iPlayer *, iBool isPaused);
 void    setVolume_Player        (iPlayer *, float volume);
 void    setFlags_Player         (iPlayer *, int flags, iBool set);
+void    setNotIdle_Player       (iPlayer *);
 
 int     flags_Player            (const iPlayer *);
 const iString *tag_Player       (const iPlayer *, enum iPlayerTag tag);
@@ -64,4 +65,5 @@ float   time_Player             (const iPlayer *);
 float   duration_Player         (const iPlayer *);
 float   streamProgress_Player   (const iPlayer *); /* normalized 0...1 */
 
+uint32_t    idleTimeMs_Player       (const iPlayer *);
 iString *   metadataLabel_Player    (const iPlayer *);
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 1a7bf4a4..85c17a5b 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -460,7 +460,12 @@ static void animatePlayingAudio_DocumentWidget_(void *widget) {
     if (document_App() != d) return;
     iConstForEach(PtrArray, i, &d->visiblePlayers) {
         const iGmRun *run = i.ptr;
-        iPlayer *plr = audioPlayer_Media(media_GmDocument(d->doc), run->audioId);
+        iPlayer *     plr = audioPlayer_Media(media_GmDocument(d->doc), run->audioId);
+        if (idleTimeMs_Player(plr) > 3000 && ~flags_Player(plr) & volumeGrabbed_PlayerFlag &&
+            flags_Player(plr) & adjustingVolume_PlayerFlag) {
+            setFlags_Player(plr, adjustingVolume_PlayerFlag, iFalse);
+            refresh_Widget(d);
+        }
         if (isStarted_Player(plr) && !isPaused_Player(plr)) {
             refresh_Widget(d);
             addTicker_App(animatePlayingAudio_DocumentWidget_, d);
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.9/cdiff/3d723de1022d2fdeccb9bae6f934e6936445ef21
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
39.390476 milliseconds
Gemini-to-HTML Time
0.23666 milliseconds

This content has been proxied by September (ba2dc).