win32: quantize taskbar playback position into uint8 range

Also, if the position is valid, set it to 1 / INF. Windows interprets 0
as non-progress.

Progress is quantized into uint8 range, it is good enough for this
use-case. This avoids unnecessary vo_control and
ITaskbarList3::SetProgressValue calls and should be visually
indistinguishable in practice.

Fixes #14282
This commit is contained in:
Kacper Michajłow 2024-06-03 03:22:23 +02:00
parent d3b251bb99
commit 37127276cc
3 changed files with 17 additions and 8 deletions

View File

@ -15,10 +15,11 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stddef.h>
#include <stdbool.h>
#include <errno.h>
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include "mpv_talloc.h"
@ -191,17 +192,18 @@ void update_vo_playback_state(struct MPContext *mpctx)
{
if (mpctx->video_out && mpctx->video_out->config_ok) {
struct voctrl_playback_state oldstate = mpctx->vo_playback_state;
double pos = get_current_pos_ratio(mpctx, false);
struct voctrl_playback_state newstate = {
.taskbar_progress = mpctx->opts->vo->taskbar_progress,
.taskbar_progress = mpctx->opts->vo->taskbar_progress && pos >= 0,
.playing = mpctx->playing,
.paused = mpctx->paused,
.percent_pos = get_percent_pos(mpctx),
.position = pos > 0 ? lrint(pos * UINT8_MAX) : 0,
};
if (oldstate.taskbar_progress != newstate.taskbar_progress ||
oldstate.playing != newstate.playing ||
oldstate.paused != newstate.paused ||
oldstate.percent_pos != newstate.percent_pos)
oldstate.position != newstate.position)
{
// Don't update progress bar if it was and still is hidden
if ((oldstate.playing && oldstate.taskbar_progress) ||

View File

@ -149,7 +149,7 @@ struct voctrl_playback_state {
bool taskbar_progress;
bool playing;
bool paused;
int percent_pos;
uint8_t position;
};
// VOCTRL_PERFORMANCE_DATA

View File

@ -767,8 +767,15 @@ static void update_playback_state(struct vo_w32_state *w32)
return;
}
ULONGLONG completed = pstate->position;
ULONGLONG total = UINT8_MAX;
if (!pstate->position) {
completed = 1;
total = MAXULONGLONG;
}
ITaskbarList3_SetProgressValue(w32->taskbar_list3, w32->window,
pstate->percent_pos, 100);
completed, total);
ITaskbarList3_SetProgressState(w32->taskbar_list3, w32->window,
pstate->paused ? TBPF_PAUSED :
TBPF_NORMAL);