Skip to content

Commit

Permalink
Turn auto-next into slideshow option
Browse files Browse the repository at this point in the history
So basically auto-next was rebranded and also now
passes "loop loop-playlist" for you. You may override
this by passing your own mpv options (loop-file=no)
if you wish.
  • Loading branch information
GhostNaN committed Aug 23, 2021
1 parent bee5808 commit 57c24c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/holder.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static void parse_command_line(int argc, char **argv, struct wl_state *state) {
{"fork", no_argument, NULL, 'f'},
{"auto-pause", no_argument, NULL, 'p'},
{"auto-stop", no_argument, NULL, 's'},
{"auto-next", required_argument, NULL, 'n'},
{"slideshow", required_argument, NULL, 'n'},
{"layer", required_argument, NULL, 'l'},
{"mpv-options", required_argument, NULL, 'o'},
{0, 0, 0, 0}
Expand Down
25 changes: 16 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static struct {

static pthread_t threads[5];

static uint AUTO_NEXT_TIME = 0;
static uint SLIDESHOW_TIME = 0;
static bool VERBOSE = 0;

static void nop() {}
Expand Down Expand Up @@ -346,8 +346,8 @@ static void *handle_mpv_events() {
time_t start_time = time(NULL);

while (!halt_info.kill_render_loop) {
if (AUTO_NEXT_TIME) {
if ((time(NULL) - start_time) >= AUTO_NEXT_TIME) {
if (SLIDESHOW_TIME) {
if ((time(NULL) - start_time) >= SLIDESHOW_TIME) {
mpv_command_async(mpv, 0, (const char*[]) {"playlist-next", NULL});
start_time = time(NULL);
}
Expand Down Expand Up @@ -430,6 +430,12 @@ static void set_init_mpv_options() {
if (VERBOSE && strcmp(loaded_configs, ""))
cflp_info("Loaded [ %s] user configs from \"~/.config/mpv/\"", loaded_configs);

// Convenience options passed for slideshow mode
if (SLIDESHOW_TIME != 0) {
mpv_set_option_string(mpv, "loop", "yes");
mpv_set_option_string(mpv, "loop-playlist", "yes");
}

// Set mpv_options passed
mpv_load_config_file(mpv, "/tmp/mpvpaper.conf");
remove("/tmp/mpvpaper.conf");
Expand Down Expand Up @@ -788,7 +794,7 @@ static void parse_command_line(int argc, char **argv, struct wl_state *state) {
{"fork", no_argument, NULL, 'f'},
{"auto-pause", no_argument, NULL, 'p'},
{"auto-stop", no_argument, NULL, 's'},
{"auto-next", required_argument, NULL, 'n'},
{"slideshow", required_argument, NULL, 'n'},
{"layer", required_argument, NULL, 'l'},
{"mpv-options", required_argument, NULL, 'o'},
{0, 0, 0, 0}
Expand All @@ -805,7 +811,8 @@ static void parse_command_line(int argc, char **argv, struct wl_state *state) {
" This saves CPU usage, more or less, seamlessly\n"
"--auto-stop -s Automagically stop mpv when the wallpaper is hidden\n"
" This saves CPU/RAM usage, although more abruptly\n"
"--auto-next -n SECS Play the next video in a playlist every ? seconds\n"
"--slideshow -n SECS Slideshow mode plays the next video in a playlist every ? seconds\n"
" And passes mpv options \"loop loop-playlist\" for convenience\n"
"--layer -l LAYER Specifies shell surface layer to run on (background by default)\n"
"--mpv-options -o \"OPTIONS\" Forwards mpv options (Must be within quotes\"\")\n";

Expand Down Expand Up @@ -841,10 +848,10 @@ static void parse_command_line(int argc, char **argv, struct wl_state *state) {
halt_info.auto_pause = 0;
break;
case 'n':
AUTO_NEXT_TIME = atoi(optarg);
if (AUTO_NEXT_TIME == 0)
cflp_warning("0 or invaild time set for auto-next\n"
"Please use a postitive integer");
SLIDESHOW_TIME = atoi(optarg);
if (SLIDESHOW_TIME == 0)
cflp_warning("0 or invalid time set for slideshow\n"
"Please use a positive integer");
break;
case 'l':
layer_name = strdup(optarg);
Expand Down

0 comments on commit 57c24c0

Please sign in to comment.