diff options
Diffstat (limited to 'src/tui.c')
| -rw-r--r-- | src/tui.c | 141 |
1 files changed, 71 insertions, 70 deletions
@@ -54,7 +54,7 @@ static bool toggle_current_tag(void); static void select_only_current_tag(void); static void seek_next_selected_tag(void); static void delete_current_tag(void); -static bool tag_name_cmp(struct link *l1, struct link *l2); +static bool tag_name_cmp(const void *p1, const void *p2, void *user); static void sort_visible_tags(void); static bool tag_pane_input(wint_t c); static void tag_pane_vis(struct pane *pane, int sel); @@ -66,7 +66,7 @@ static bool rename_current_track(void); static bool delete_current_track(void); static void queue_current_track(void); static void unqueue_last_track(void); -static bool track_vis_name_cmp(struct link *l1, struct link *l2); +static bool track_vis_name_cmp(const void *p1, const void *p2, void *user); static void sort_visible_tracks(void); static bool track_pane_input(wint_t c); static void track_pane_vis(struct pane *pane, int sel); @@ -215,8 +215,8 @@ command_name_gen(const char *text, int fwd, int reset) char * track_vis_name_gen(const char *text, int fwd, int reset) { - static struct link *cur; - struct link *link; + static struct list_link *cur; + struct list_link *link; struct track *track; const char *prevname; char *dup; @@ -256,8 +256,8 @@ next: char * track_name_gen(const char *text, int fwd, int reset) { - static struct link *cur; - struct link *link; + static struct list_link *cur; + struct list_link *link; struct track *track; const char *prevname; char *dup; @@ -270,13 +270,13 @@ track_name_gen(const char *text, int fwd, int reset) link = fwd ? cur->next : cur->prev; prevname = NULL; if (LIST_INNER(cur)) { - track = UPCAST(cur, struct track, link); + track = LIST_UPCAST(cur, struct track, link); prevname = track->name; } } while (LIST_INNER(link)) { - track = UPCAST(link, struct track, link); + track = LIST_UPCAST(link, struct track, link); if (prevname && !strcmp(prevname, track->name)) goto next; @@ -297,8 +297,8 @@ next: char * tag_name_gen(const char *text, int fwd, int reset) { - static struct link *cur; - struct link *link; + static struct list_link *cur; + struct list_link *link; struct tag *tag; char *dup; @@ -310,7 +310,7 @@ tag_name_gen(const char *text, int fwd, int reset) } while (LIST_INNER(link)) { - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); if (strcasestr(tag->name, text)) { cur = link; dup = astrdup(tag->name); @@ -325,13 +325,13 @@ tag_name_gen(const char *text, int fwd, int reset) bool rename_current_tag(void) { - struct link *link; + struct list_link *link; struct tag *tag; char *cmd; link = list_at(&tags, tag_nav.sel); if (!link) return false; - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); cmd = aprintf("rename %s", tag->name); select_cmd_pane(IMODE_EXECUTE); @@ -344,20 +344,20 @@ rename_current_tag(void) bool toggle_current_tag(void) { - struct link *link; + struct list_link *link; struct tag *tag; if (list_empty(&tags)) return false; link = list_at(&tags, tag_nav.sel); if (!link) return false; - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); /* toggle tag in tags_sel */ - if (link_inuse(&tag->link_sel)) { - link_pop(&tag->link_sel); + if (list_link_inuse(&tag->link_sel)) { + list_link_pop(&tag->link_sel); } else { - list_push_back(&tags_sel, &tag->link_sel); + list_insert_back(&tags_sel, &tag->link_sel); } playlist_outdated = true; @@ -375,7 +375,7 @@ select_only_current_tag(void) void seek_next_selected_tag(void) { - struct link *link; + struct list_link *link; struct tag *tag; int index; @@ -389,7 +389,7 @@ seek_next_selected_tag(void) if (!link) return; index = tag_nav.sel; - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); do { index += 1; link = tag->link.next; @@ -397,8 +397,8 @@ seek_next_selected_tag(void) link = list_at(&tags, 0); index = 0; } - tag = UPCAST(link, struct tag, link); - } while (!link_inuse(&tag->link_sel)); + tag = LIST_UPCAST(link, struct tag, link); + } while (!list_link_inuse(&tag->link_sel)); listnav_update_sel(&tag_nav, index); } @@ -406,7 +406,7 @@ seek_next_selected_tag(void) void delete_current_tag(void) { - struct link *link; + struct list_link *link; struct tag *tag; if (!confirm_popup("Delete tag?")) @@ -414,19 +414,16 @@ delete_current_tag(void) link = list_at(&tags, tag_nav.sel); if (!link) return; - tag = UPCAST(link, struct tag, link); - if (link_inuse(&tag->link_sel)) + tag = LIST_UPCAST(link, struct tag, link); + if (list_link_inuse(&tag->link_sel)) playlist_outdated = true; tag_rm(tag, true); } bool -tag_name_cmp(struct link *l1, struct link *l2) +tag_name_cmp(const void *p1, const void *p2, void *user) { - struct tag *t1, *t2; - - t1 = LINK_UPCAST(l1, struct tag, link); - t2 = LINK_UPCAST(l2, struct tag, link); + const struct tag *t1 = p1, *t2 = p2; return strcasecmp(t1->name, t2->name) <= 0; } @@ -434,7 +431,8 @@ tag_name_cmp(struct link *l1, struct link *l2) void sort_visible_tags(void) { - list_sort(&tags, false, tag_name_cmp); + list_insertion_sort(&tags, false, tag_name_cmp, + LIST_OFFSET(struct tag, link), NULL); } bool @@ -488,7 +486,7 @@ void tag_pane_vis(struct pane *pane, int sel) { struct tag *tag; - struct link *link; + struct list_link *link; int index, tagsel; werase(pane->win); @@ -499,8 +497,8 @@ tag_pane_vis(struct pane *pane, int sel) index = -1; for (LIST_ITER(&tags, link)) { - tag = UPCAST(link, struct tag, link); - tagsel = link_inuse(&tag->link_sel); + tag = LIST_UPCAST(link, struct tag, link); + tagsel = list_link_inuse(&tag->link_sel); index += 1; if (index < tag_nav.wmin) continue; @@ -531,7 +529,7 @@ tag_pane_vis(struct pane *pane, int sel) bool play_current_track(void) { - struct link *link; + struct list_link *link; struct track *track; link = list_at(tracks_vis, track_nav.sel); @@ -561,7 +559,7 @@ nav_to_track_tag(struct track *target) bool nav_to_track(struct track *target) { - struct link *link; + struct list_link *link; struct track *track; int index; @@ -583,7 +581,7 @@ nav_to_track(struct track *target) bool rename_current_track(void) { - struct link *link; + struct list_link *link; struct track *track; char *cmd; @@ -602,7 +600,7 @@ rename_current_track(void) bool delete_current_track(void) { - struct link *link; + struct list_link *link; struct track *track; link = list_at(tracks_vis, track_nav.sel); @@ -626,33 +624,30 @@ delete_current_track(void) void queue_current_track(void) { - struct link *link; + struct list_link *link; struct track *track; link = list_at(tracks_vis, track_nav.sel); if (!link) return; track = tracks_vis_track(link); - list_push_back(&player.queue, &track->link_pq); + list_insert_back(&player.queue, &track->link_pq); } void unqueue_last_track(void) { - struct link *link; + struct list_link *link; link = list_back(&player.queue); if (!link) return; - link_pop(link); + list_link_pop(link); } bool -track_vis_name_cmp(struct link *l1, struct link *l2) +track_vis_name_cmp(const void *p1, const void *p2, void *user) { - struct track *t1, *t2; - - t1 = tracks_vis_track(l1); - t2 = tracks_vis_track(l2); + const struct track *t1 = p1, *t2 = p2; return strcasecmp(t1->name, t2->name) <= 0; } @@ -660,15 +655,21 @@ track_vis_name_cmp(struct link *l1, struct link *l2) void sort_visible_tracks(void) { - struct link *link; + struct list_link *link; struct tag *tag; - list_sort(tracks_vis, false, track_vis_name_cmp); + if (tracks_vis == &player.playlist) { + list_insertion_sort(tracks_vis, false, track_vis_name_cmp, + LIST_OFFSET(struct track, link_pl), NULL); + } else { + list_insertion_sort(tracks_vis, false, track_vis_name_cmp, + LIST_OFFSET(struct track, link_tt), NULL); + } if (!track_show_playlist) { link = list_at(&tags, tag_nav.sel); if (!link) return; - tag = LINK_UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); tag->reordered = true; } } @@ -729,7 +730,7 @@ void track_pane_vis(struct pane *pane, int sel) { struct track *track; - struct link *link; + struct list_link *link; struct tag *tag; int index; @@ -741,7 +742,7 @@ track_pane_vis(struct pane *pane, int sel) if (!link) { pane_title(pane, sel, "Tracks"); } else { - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); pane_title(pane, sel, "Tracks (%s)", tag->name); } } @@ -838,10 +839,10 @@ bool play_track(const char *query) { struct track *track; - struct link *link; + struct list_link *link; for (LIST_ITER(&tracks, link)) { - track = UPCAST(link, struct track, link); + track = LIST_UPCAST(link, struct track, link); if (!strcmp(track->name, query)) { player_play_track(track, true); return true; @@ -856,7 +857,7 @@ nav_to_track_by_name(const char *query) { struct track *track; struct tag *tag; - struct link *link; + struct list_link *link; const char *qtrack; const char *qtag; @@ -866,7 +867,7 @@ nav_to_track_by_name(const char *query) qtrack += 1; for (LIST_ITER(&tags, link)) { - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); if (!strncmp(tag->name, qtag, qtrack - qtag - 1)) break; } @@ -874,7 +875,7 @@ nav_to_track_by_name(const char *query) return false; for (LIST_ITER(&tag->tracks, link)) { - track = UPCAST(link, struct track, link_tt); + track = LIST_UPCAST(link, struct track, link_tt); if (!strcmp(track->name, qtrack)) { nav_to_track_tag(track); nav_to_track(track); @@ -890,7 +891,7 @@ bool nav_to_track_vis_by_name(const char *query) { struct track *track; - struct link *link; + struct list_link *link; for (LIST_ITER(tracks_vis, link)) { track = tracks_vis_track(link); @@ -908,13 +909,13 @@ bool seek_tag(const char *query) { struct tag *tag; - struct link *link; + struct list_link *link; int index; index = -1; for (LIST_ITER(&tags, link)) { index += 1; - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); if (!strcmp(tag->name, query)) { listnav_update_sel(&tag_nav, index); pane_after_cmd = tag_pane; @@ -1025,7 +1026,7 @@ cmd_pane_vis(struct pane *pane, int sel) { static struct strbuf line = { 0 }; struct inputln *cmd; - struct link *link; + struct list_link *link; int index, offset; werase(pane->win); @@ -1100,7 +1101,7 @@ cmd_pane_vis(struct pane *pane, int sel) if (cmd != history->input) { index = 0; for (LIST_ITER(&history->list, link)) { - if (UPCAST(link, struct inputln, link) == cmd) + if (LIST_UPCAST(link, struct inputln, link) == cmd) break; index += 1; } @@ -1135,7 +1136,7 @@ cmd_pane_vis(struct pane *pane, int sel) void update_tracks_vis(void) { - struct link *link; + struct list_link *link; struct tag *tag; if (track_show_playlist) { @@ -1143,7 +1144,7 @@ update_tracks_vis(void) } else { link = list_at(&tags, tag_nav.sel); if (!link) return; - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); tracks_vis = &tag->tracks; } @@ -1153,7 +1154,7 @@ update_tracks_vis(void) void reindex_selected_tags(void) { - struct link *link; + struct list_link *link; struct tag *tag; struct track *track; struct tag *playing_tag; @@ -1169,19 +1170,19 @@ reindex_selected_tags(void) if (track_show_playlist) { for (LIST_ITER(&tags_sel, link)) { - tag = UPCAST(link, struct tag, link_sel); + tag = LIST_UPCAST(link, struct tag, link_sel); tag_reindex_tracks(tag); } } else { link = list_at(&tags, tag_nav.sel); if (!link) return; - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); tag_reindex_tracks(tag); } if (playing_tag) { for (LIST_ITER(&playing_tag->tracks, link)) { - track = UPCAST(link, struct track, link_tt); + track = LIST_UPCAST(link, struct track, link_tt); if (!strcmp(track->name, playing_name)) { player.track = track; break; @@ -1337,7 +1338,7 @@ tui_curses_init(void) void tui_resize(void) { - struct link *link; + struct list_link *link; struct tag *tag; int leftw; @@ -1354,7 +1355,7 @@ tui_resize(void) /* adjust tag pane width to name lengths */ leftw = 0; for (LIST_ITER(&tags, link)) { - tag = UPCAST(link, struct tag, link); + tag = LIST_UPCAST(link, struct tag, link); leftw = MAX(leftw, strlen(tag->name)); } leftw = MAX(leftw + 1, 0.2f * scrw); |
