Skip to content

Commit

Permalink
Add auto_hide_playlists_panel option
Browse files Browse the repository at this point in the history
(Terminology is a bit difficult here, it's not really a tree and
"playlists list" doesn't quite roll off the tongue...)

Requested in cmus#897, etc.
  • Loading branch information
gavtroy authored and flyingmutant committed Jul 8, 2023
1 parent 7d31169 commit c0795e3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,10 @@ auto_expand_albums_follow, auto_expand_albums_search, auto_expand_albums_selcur
option. Any "auto_expand_albums_\* = false" implies "show_all_tracks =
true".

auto_hide_playlists_panel (false)
Hide the left panel in playlist view. The panel will show as needed when
activated with win-next (*tab*).

auto_reshuffle (true)
Reshuffle a playlist when the end of a shuffled list is reached.

Expand Down
17 changes: 17 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ int skip_track_info = 0;
int auto_expand_albums_follow = 1;
int auto_expand_albums_search = 1;
int auto_expand_albums_selcur = 1;
int auto_hide_playlists_panel = 0;
int show_all_tracks = 1;
int mouse = 0;
int mpris = 1;
Expand Down Expand Up @@ -509,6 +510,21 @@ static void set_tree_width_max(void *data, const char *buf)

/* callbacks for toggle options {{{ */

static void get_auto_hide_playlists_panel(void *data, char *buf, size_t size)
{
strscpy(buf, bool_names[auto_hide_playlists_panel], size);
}

static void set_auto_hide_playlists_panel(void *data, const char *buf)
{
parse_bool(buf, &auto_hide_playlists_panel);
}

static void toggle_auto_hide_playlists_panel(void *data)
{
auto_hide_playlists_panel ^= 1;
}

static void get_auto_reshuffle(void *data, char *buf, size_t size)
{
strscpy(buf, bool_names[auto_reshuffle], size);
Expand Down Expand Up @@ -1461,6 +1477,7 @@ static const struct {
DT(auto_expand_albums_follow)
DT(auto_expand_albums_search)
DT(auto_expand_albums_selcur)
DT(auto_hide_playlists_panel)
DT(show_all_tracks)
DT(show_current_bitrate)
DT(show_playback_position)
Expand Down
1 change: 1 addition & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ extern char *server_password;
extern int auto_expand_albums_follow;
extern int auto_expand_albums_search;
extern int auto_expand_albums_selcur;
extern int auto_hide_playlists_panel;
extern int show_all_tracks;
extern int auto_reshuffle;
extern int confirm_run;
Expand Down
16 changes: 16 additions & 0 deletions pl.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ void pl_init(void)
pl_searchable = searchable_new(NULL, &iter, &pl_searchable_ops);
}

void pl_init_options(void)
{
if (auto_hide_playlists_panel)
pl_cursor_in_track_window = 1;
}

void pl_exit(void)
{
pl_save_all();
Expand Down Expand Up @@ -864,6 +870,16 @@ void pl_set_nr_rows(int h)
window_set_nr_rows(pl_editable_shared.win, h);
}

bool pl_show_panel(void)
{
return !auto_hide_playlists_panel || !pl_cursor_in_track_window;
}

char *pl_visible_get_name(void)
{
return pl_visible->name;
}

unsigned int pl_visible_total_time(void)
{
return pl_visible->editable.total_time;
Expand Down
3 changes: 3 additions & 0 deletions pl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern struct window *pl_list_win;
extern struct editable_shared pl_editable_shared;

void pl_init(void);
void pl_init_options(void);
void pl_exit(void);
void pl_save(void);
void pl_import(const char *path);
Expand All @@ -58,6 +59,8 @@ int pl_for_each_sel(track_info_cb cb, void *data, int reverse, int advance);
void pl_reload_visible(void);
struct window *pl_cursor_win(void);
void pl_set_nr_rows(int h);
bool pl_show_panel(void);
char *pl_visible_get_name(void);
unsigned int pl_visible_total_time(void);
unsigned int pl_playing_total_time(void);
struct simple_track *pl_get_playing_track(void);
Expand Down
47 changes: 30 additions & 17 deletions ui_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,23 @@ static void print_pl_list(struct window *win, int row, struct iter *iter)
dump_print_buffer(row + 1, 0);
}

static void draw_separator(void)
{
int row;

bkgdset(pairs[CURSED_WIN_TITLE]);
(void) mvaddch(0, tree_win_w, ' ');
bkgdset(pairs[CURSED_SEPARATOR]);
for (row = 1; row < LINES - 3; row++)
(void) mvaddch(row, tree_win_w, ACS_VLINE);
}

static void update_pl_list(struct window *win)
{
update_window(win, tree_win_x, 0, tree_win_w + 1, "Playlist", print_pl_list);
if (pl_show_panel()) {
update_window(win, tree_win_x, 0, tree_win_w + 1, "Playlist", print_pl_list);
draw_separator();
}
}

static void update_pl_tracks(struct window *win)
Expand All @@ -987,15 +1001,25 @@ static void update_pl_tracks(struct window *win)
gbuf_clear(&title);
int win_w_tmp = win_w;

win_x = track_win_x;
win_w = track_win_w;
if (pl_show_panel()) {
win_x = track_win_x;
win_w = track_win_w;
} else {
win_x = 0;
win_w = tree_win_w + 1 + track_win_w;
}
win_active = pl_get_cursor_in_track_window();

get_global_fopts();
fopt_set_time(&track_fopts[TF_TOTAL], pl_visible_total_time(), 0);

format_print(&title, track_win_w - 2, "Track%= %{total}", track_fopts);
update_window(win, track_win_x, 0, track_win_w, title.buffer, print_editable);
if (pl_show_panel()) {
format_print(&title, win_w - 2, "Track%= %{total}", track_fopts);
} else {
fopt_set_str(&track_fopts[TF_TITLE], pl_visible_get_name());
format_print(&title, win_w - 2, "Playlist - %{title}%= %{total}", track_fopts);
}
update_window(win, win_x, 0, win_w, title.buffer, print_editable);

win_active = 1;
win_x = 0;
Expand Down Expand Up @@ -1088,22 +1112,10 @@ static void update_help_window(void)
update_window(help_win, 0, 0, win_w, "Settings", print_help);
}

static void draw_separator(void)
{
int row;

bkgdset(pairs[CURSED_WIN_TITLE]);
(void) mvaddch(0, tree_win_w, ' ');
bkgdset(pairs[CURSED_SEPARATOR]);
for (row = 1; row < LINES - 3; row++)
(void) mvaddch(row, tree_win_w, ACS_VLINE);
}

static void update_pl_view(int full)
{
current_track = pl_get_playing_track();
pl_draw(update_pl_list, update_pl_tracks, full);
draw_separator();
}

static void do_update_view(int full)
Expand Down Expand Up @@ -2345,6 +2357,7 @@ static void init_all(void)

/* almost everything must be initialized now */
options_load();
pl_init_options();
if (mpris)
mpris_init();

Expand Down

0 comments on commit c0795e3

Please sign in to comment.