diff --git a/src/screen_help.c b/src/screen_help.c
index 681bc6cfe5198d81ee65ee39630dfef28b3a54eb..79b8fa722ef146a9e638be46515285f42644da07 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
#include "command.h"
#include "screen.h"
#include "screen_utils.h"
+#include "gcc.h"
#include <stdlib.h>
#include <string.h>
#ifdef ENABLE_SEARCH_SCREEN
{ 0, CMD_SCREEN_SEARCH, NULL },
#endif
-#ifdef ENABLE_CLOCK_SCREEN
- { 0, CMD_SCREEN_CLOCK, NULL },
-#endif
#ifdef ENABLE_KEYDEF_SCREEN
{ 0, CMD_SCREEN_KEYDEF, NULL },
#endif
{ 2, CMD_NONE, NULL },
{ 0, CMD_STOP, NULL },
{ 0, CMD_PAUSE, NULL },
+ { 0, CMD_CROP, NULL },
{ 0, CMD_TRACK_NEXT, NULL },
{ 0, CMD_TRACK_PREVIOUS, NULL },
{ 0, CMD_SEEK_FORWARD, NULL },
{ 0, CMD_LYRICS_UPDATE, N_("Explicitly download lyrics") },
{ 0, CMD_ADD, N_("Save lyrics") },
#endif
- { 0, CMD_NONE, NULL },
- {-1, CMD_NONE, NULL }
};
-static int help_text_rows = -1;
+#define help_text_rows (sizeof(help_text) / sizeof(help_text[0]))
+
static list_window_t *lw = NULL;
static const char *
-list_callback(unsigned idx, int *highlight, void *data)
+list_callback(unsigned idx, int *highlight, mpd_unused void *data)
{
static char buf[512];
- if (help_text_rows < 0) {
- help_text_rows = 0;
- while (help_text[help_text_rows].highlight != -1)
- help_text_rows++;
- }
-
- *highlight = 0;
- if (idx < (unsigned)help_text_rows) {
- *highlight = help_text[idx].highlight > 0;
- if (help_text[idx].command == CMD_NONE) {
- if (help_text[idx].text)
- g_snprintf(buf, sizeof(buf), " %s", _(help_text[idx].text));
- else if (help_text[idx].highlight == 2) {
- int i;
+ if (idx >= help_text_rows)
+ return NULL;
- for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
- buf[i] = '-';
- buf[i] = '\0';
- } else
- g_strlcpy(buf, " ", sizeof(buf));
- return buf;
- }
+ if (help_text[idx].highlight)
+ *highlight = 1;
+ if (help_text[idx].command == CMD_NONE) {
if (help_text[idx].text)
- g_snprintf(buf, sizeof(buf),
- "%20s : %s ",
- get_key_names(help_text[idx].command, TRUE),
- _(help_text[idx].text));
- else
- g_snprintf(buf, sizeof(buf),
- "%20s : %s ",
- get_key_names(help_text[idx].command, TRUE),
- get_key_description(help_text[idx].command));
+ g_snprintf(buf, sizeof(buf), " %s", _(help_text[idx].text));
+ else if (help_text[idx].highlight == 2) {
+ int i;
+
+ for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
+ buf[i] = '-';
+ buf[i] = '\0';
+ } else
+ g_strlcpy(buf, " ", sizeof(buf));
return buf;
}
- return NULL;
+ if (help_text[idx].text)
+ g_snprintf(buf, sizeof(buf),
+ "%20s : %s ",
+ get_key_names(help_text[idx].command, TRUE),
+ _(help_text[idx].text));
+ else
+ g_snprintf(buf, sizeof(buf),
+ "%20s : %s ",
+ get_key_names(help_text[idx].command, TRUE),
+ get_key_description(help_text[idx].command));
+ return buf;
}
static void
static const char *
-help_title(char *str, size_t size)
+help_title(mpd_unused char *str, mpd_unused size_t size)
{
return _("Help");
}
static void
-help_paint(screen_t *screen, mpdclient_t *c)
+help_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c)
{
lw->clear = 1;
list_window_paint(lw, list_callback, NULL);
wrefresh(lw->w);
}
-static void
-help_update(screen_t *screen, mpdclient_t *c)
+static int
+help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd)
{
- if (lw->repaint) {
+ if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
list_window_paint(lw, list_callback, NULL);
wrefresh(lw->w);
- lw->repaint = 0;
- }
-}
-
-
-static int
-help_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
-{
- lw->repaint=1;
- lw->clear=1;
- switch(cmd) {
- case CMD_LIST_NEXT:
- if (lw->start + lw->rows < (unsigned)help_text_rows)
- lw->start++;
- return 1;
- case CMD_LIST_PREVIOUS:
- if (lw->start > 0)
- lw->start--;
- return 1;
- case CMD_LIST_FIRST:
- lw->start = 0;
return 1;
- case CMD_LIST_LAST:
- if ((unsigned)help_text_rows > lw->rows)
- lw->start = help_text_rows - lw->rows;
- else
- lw->start = 0;
- return 1;
- case CMD_LIST_NEXT_PAGE:
- lw->start = lw->start + lw->rows;
- if (lw->start + lw->rows >= (unsigned)help_text_rows) {
- if ((unsigned)help_text_rows > lw->rows)
- lw->start = help_text_rows - lw->rows;
- else
- lw->start = 0;
- }
- return 1;
- case CMD_LIST_PREVIOUS_PAGE:
- if (lw->start > lw->rows)
- lw->start -= lw->rows;
- else
- lw->start = 0;
- return 1;
- default:
- break;
}
lw->selected = lw->start+lw->rows;
lw, help_text_rows,
cmd, list_callback, NULL)) {
/* center the row */
- if (lw->selected > lw->rows / 2)
- lw->start = lw->selected - lw->rows / 2;
- else
- lw->start = 0;
- if (lw->start + lw->rows > (unsigned)help_text_rows) {
- if (lw->rows < (unsigned)help_text_rows)
- lw->start = help_text_rows - lw->rows;
- else
- lw->start = 0;
- }
+ list_window_center(lw, help_text_rows, lw->selected);
+ list_window_paint(lw, list_callback, NULL);
+ wrefresh(lw->w);
return 1;
}
return 0;
}
-static list_window_t *
-help_lw(void)
-{
- return lw;
-}
-
-screen_functions_t *
-get_screen_help(void)
-{
- static screen_functions_t functions;
-
- memset(&functions, 0, sizeof(screen_functions_t));
- functions.init = help_init;
- functions.exit = help_exit;
- functions.open = NULL;
- functions.close = NULL;
- functions.resize = help_resize;
- functions.paint = help_paint;
- functions.update = help_update;
- functions.cmd = help_cmd;
- functions.get_lw = help_lw;
- functions.get_title = help_title;
-
- return &functions;
-}
+const struct screen_functions screen_help = {
+ .init = help_init,
+ .exit = help_exit,
+ .resize = help_resize,
+ .paint = help_paint,
+ .cmd = help_cmd,
+ .get_title = help_title,
+};