Skip to content

Commit

Permalink
Add tree width options (cmus#1018)
Browse files Browse the repository at this point in the history
* Add tree_width_percent option (cmus#990)

* Add tree_width_max option
  • Loading branch information
pgaskin authored Dec 13, 2020
1 parent 2aa28a1 commit 0e8632d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
34 changes: 34 additions & 0 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,40 @@ stop_after_queue (false)
time_show_leading_zero (true)
Pad durations of less than 10 minutes with a leading 0

tree_width_percent (33) [1-100]
Percentage of window to use for left pane.

tree_width_max (0) [0-9999]
Restrict the size calculated from tree_width_percent. 0 disables this
option.

This affects the tree in the library view and the playlist list in the
playlist view.

Note that this value will be further constrained by the window width
and/or the minimum tree size.

For example, to set a fixed size of 60 columns:

@pre
set tree_width_percent=100
set tree_width_max=60
@endpre

Or, to be 33% wide, but at most 60 columns

@pre
set tree_width_percent=33
set tree_width_max=60
@endpre

Or, to always be 33% wide where possible (the default behavior):

@pre
set tree_width_percent=33
set tree_width_max=0
@endpre

wrap_search (true)
Controls whether the search wraps around the end.

Expand Down
32 changes: 32 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ int mpris = 1;
int time_show_leading_zero = 1;
int start_view = TREE_VIEW;
int stop_after_queue = 0;
int tree_width_percent = 33;
int tree_width_max = 0;

int colors[NR_COLORS] = {
-1,
Expand Down Expand Up @@ -470,6 +472,34 @@ static void set_status_display_program(void *data, const char *buf)
status_display_program = expand_filename(buf);
}

static void get_tree_width_percent(void *data, char *buf, size_t size)
{
buf_int(buf, tree_width_percent, size);
}

static void set_tree_width_percent(void *data, const char *buf)
{
int percent;

if (parse_int(buf, 1, 100, &percent))
tree_width_percent = percent;
update_size();
}

static void get_tree_width_max(void *data, char *buf, size_t size)
{
buf_int(buf, tree_width_max, size);
}

static void set_tree_width_max(void *data, const char *buf)
{
int cols;

if (parse_int(buf, 0, 9999, &cols))
tree_width_max = cols;
update_size();
}

/* }}} */

/* callbacks for toggle options {{{ */
Expand Down Expand Up @@ -1401,6 +1431,8 @@ static const struct {
DN(lib_add_filter)
DN(start_view)
DT(stop_after_queue)
DN(tree_width_percent)
DN(tree_width_max)
{ NULL, NULL, NULL, NULL, 0 }
};

Expand Down
2 changes: 2 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ extern int mpris;
extern int time_show_leading_zero;
extern int start_view;
extern int stop_after_queue;
extern int tree_width_percent;
extern int tree_width_max;

extern const char * const aaa_mode_names[];
extern const char * const view_names[NR_VIEWS + 1];
Expand Down
8 changes: 7 additions & 1 deletion ui_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,10 @@ static void sig_winch(int sig)
needs_to_resize = 1;
}

void update_size(void) {
needs_to_resize = 1;
}

static int get_window_size(int *lines, int *columns)
{
struct winsize ws;
Expand All @@ -1920,7 +1924,9 @@ static int get_window_size(int *lines, int *columns)

static void resize_tree_view(int w, int h)
{
tree_win_w = w / 3;
tree_win_w = w * ((float)tree_width_percent / 100.0f);
if (tree_width_max && tree_win_w > tree_width_max)
tree_win_w = tree_width_max;
track_win_w = w - tree_win_w - 1;
if (tree_win_w < 8)
tree_win_w = 8;
Expand Down
1 change: 1 addition & 0 deletions ui_curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void update_statusline(void);
void update_filterline(void);
void update_colors(void);
void update_full(void);
void update_size(void);
void info_msg(const char *format, ...) CMUS_FORMAT(1, 2);
void error_msg(const char *format, ...) CMUS_FORMAT(1, 2);
enum ui_query_answer yes_no_query(const char *format, ...) CMUS_FORMAT(1, 2);
Expand Down

0 comments on commit 0e8632d

Please sign in to comment.