From 7ffaad197d193796d54094e737e5ec37302d2e44 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 14 Jun 2009 18:12:03 +0200 Subject: [PATCH] list_window: added the "hardware_cursor" option This option makes ncurses look a little bit ugly, but it is important for blind ncmpc users who depend on a braille display. The braille display shows the position of the hardware cursor, but is unable to display the "inverse colors" of the traditional ncmpc cursor. --- NEWS | 1 + doc/config.sample | 3 +++ doc/ncmpc.1 | 3 +++ src/conf.c | 2 ++ src/list_window.c | 9 ++++++++- src/options.h | 2 ++ src/screen.c | 27 +++++++++++++++++++-------- 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 3691658..2adcc44 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ncmpc 0.15 - not yet released * added CMD_SELECT_PLAYING * display song duration in the playlist +* added the "hardware_cursor" option ncmpc 0.14 - 2009-04-21 diff --git a/doc/config.sample b/doc/config.sample index f123bb1..ba37c98 100644 --- a/doc/config.sample +++ b/doc/config.sample @@ -60,6 +60,9 @@ ## Make the cursor as wide as the screen. #wide-cursor = yes +## Use the terminal's hardware cursor instead of inverse colors +#hardware-cursor = yes + ## Hide playlist cursor after x seconds (0 disables this feature). #hide-cursor = 5 diff --git a/doc/ncmpc.1 b/doc/ncmpc.1 index 2bca04d..c000663 100644 --- a/doc/ncmpc.1 +++ b/doc/ncmpc.1 @@ -127,6 +127,9 @@ Show a list of the screens in the top line on startup. .TP .B wide\-cursor = yes|no Make the cursor as wide as the screen. +.TP +.B hardware\-cursor = yes|no +Use the terminal's hardware cursor instead of inverse colors. .TP .B hide\-cursor = NUM Hide the playlist cursor after NUM seconds of inactivity. diff --git a/src/conf.c b/src/conf.c index 4f17108..e60fb8f 100644 --- a/src/conf.c +++ b/src/conf.c @@ -420,6 +420,8 @@ parse_line(char *line) /* wide cursor */ else if (!strcasecmp(CONF_WIDE_CURSOR, name)) options.wide_cursor = str2bool(value); + else if (strcasecmp(name, "hardware-cursor") == 0) + options.hardware_cursor = str2bool(value); /* welcome screen list */ else if (!strcasecmp(CONF_WELCOME_SCREEN_LIST, name)) options.welcome_screen_list = str2bool(value); diff --git a/src/list_window.c b/src/list_window.c index 9421db3..9f3bfc7 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -346,7 +346,8 @@ list_window_paint(struct list_window *lw, else colors_use(lw->w, COLOR_LIST); - if (show_cursor && selected) + if (show_cursor && selected && + (!options.hardware_cursor || lw->range_selection)) wattron(lw->w, A_REVERSE); //waddnstr(lw->w, label, lw->cols); @@ -375,6 +376,12 @@ list_window_paint(struct list_window *lw, } else wclrtoeol(lw->w); } + + if (options.hardware_cursor && lw->selected >= lw->start && + lw->selected < lw->start + lw->rows) { + curs_set(1); + wmove(lw->w, lw->selected - lw->start, 0); + } } bool diff --git a/src/options.h b/src/options.h index cc42493..5927d4c 100644 --- a/src/options.h +++ b/src/options.h @@ -56,6 +56,8 @@ typedef struct { int scroll_offset; bool auto_center; bool wide_cursor; + bool hardware_cursor; + #ifdef ENABLE_COLORS bool enable_colors; #endif diff --git a/src/screen.c b/src/screen.c index c4e156a..e540fec 100644 --- a/src/screen.c +++ b/src/screen.c @@ -604,14 +604,22 @@ screen_paint(mpdclient_t *c) else paint_top_window("", c, 1); + /* paint the bottom window */ + + paint_progress_window(c); + paint_status_window(c); + /* paint the main window */ + wclear(screen.main_window.w); if (mode_fn->paint != NULL) mode_fn->paint(); - paint_progress_window(c); - paint_status_window(c); - wmove(screen.main_window.w, 0, 0); + /* move the cursor to the origin */ + + if (!options.hardware_cursor) + wmove(screen.main_window.w, 0, 0); + wnoutrefresh(screen.main_window.w); /* tell curses to update */ @@ -699,18 +707,21 @@ screen_update(mpdclient_t *c) } else paint_top_window("", c, 0); - /* update the main window */ - if (mode_fn->update != NULL) - mode_fn->update(c); - /* update progress window */ paint_progress_window(c); /* update status window */ paint_status_window(c); + /* update the main window */ + if (mode_fn->update != NULL) + mode_fn->update(c); + /* move the cursor to the origin */ - wmove(screen.main_window.w, 0, 0); + + if (!options.hardware_cursor) + wmove(screen.main_window.w, 0, 0); + wnoutrefresh(screen.main_window.w); /* tell curses to update */ -- 2.30.2