From 6308bf8997a932418f71f8cc647b60df349a8580 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 28 Sep 2019 00:18:02 +0100 Subject: [PATCH] refactor: mutt_window_getxy() to mutt_window_get_coords() Encapsulate a curses function to reduce dependencies. --- curs_lib.c | 6 +++--- mutt_window.c | 24 ++++++++++++------------ mutt_window.h | 2 +- sidebar.c | 11 +++-------- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/curs_lib.c b/curs_lib.c index 797323fc3..a11b282b9 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -258,7 +258,7 @@ int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionF bool multiple, char ***files, int *numfiles) { int ret; - int x; + int col; struct EnterState *es = mutt_enter_state_new(); @@ -276,8 +276,8 @@ int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionF mutt_window_addstr(field); mutt_curses_set_color(MT_COLOR_NORMAL); mutt_refresh(); - mutt_window_getxy(MuttMessageWindow, &x, NULL); - ret = mutt_enter_string_full(buf, buflen, x, complete, multiple, files, numfiles, es); + mutt_window_get_coords(MuttMessageWindow, NULL, &col); + ret = mutt_enter_string_full(buf, buflen, col, complete, multiple, files, numfiles, es); } while (ret == 1); mutt_window_clearline(MuttMessageWindow, 0); mutt_enter_state_free(&es); diff --git a/mutt_window.c b/mutt_window.c index 909aaf8c0..71404864d 100644 --- a/mutt_window.c +++ b/mutt_window.c @@ -152,24 +152,24 @@ void mutt_window_free_all(void) } /** - * mutt_window_getxy - Get the cursor position in the Window + * mutt_window_get_coords - Get the cursor position in the Window * @param[in] win Window - * @param[out] x X-Coordinate - * @param[out] y Y-Coordinate + * @param[out] row Row in Window + * @param[out] col Column in Window * * Assumes the current position is inside the window. Otherwise it will * happily return negative or values outside the window boundaries */ -void mutt_window_getxy(struct MuttWindow *win, int *x, int *y) +void mutt_window_get_coords(struct MuttWindow *win, int *row, int *col) { - int row = 0; - int col = 0; - - getyx(stdscr, row, col); - if (x) - *x = col - win->col_offset; - if (y) - *y = row - win->row_offset; + int x = 0; + int y = 0; + + getyx(stdscr, y, x); + if (col) + *col = x - win->col_offset; + if (row) + *row = y - win->row_offset; } /** diff --git a/mutt_window.h b/mutt_window.h index 05345164f..483c3cc07 100644 --- a/mutt_window.h +++ b/mutt_window.h @@ -50,7 +50,7 @@ extern struct MuttWindow *MuttStatusWindow; void mutt_window_copy_size (const struct MuttWindow *win_src, struct MuttWindow *win_dst); void mutt_window_free (struct MuttWindow **ptr); void mutt_window_free_all (void); -void mutt_window_getxy (struct MuttWindow *win, int *x, int *y); +void mutt_window_get_coords (struct MuttWindow *win, int *col, int *row); void mutt_window_init (void); struct MuttWindow *mutt_window_new (void); void mutt_window_reflow (void); diff --git a/sidebar.c b/sidebar.c index b0ead8acb..c94706dd0 100644 --- a/sidebar.c +++ b/sidebar.c @@ -968,13 +968,8 @@ void mutt_sb_draw(void) if (!C_SidebarVisible) return; -#ifdef USE_SLANG_CURSES - int x = SLsmg_get_column(); - int y = SLsmg_get_row(); -#else - int x = getcurx(stdscr); - int y = getcury(stdscr); -#endif + int row = 0, col = 0; + mutt_window_get_coords(MuttSidebarWindow, &row, &col); int num_rows = MuttSidebarWindow->rows; int num_cols = MuttSidebarWindow->cols; @@ -999,7 +994,7 @@ void mutt_sb_draw(void) } draw_sidebar(num_rows, num_cols, div_width); - mutt_window_move_abs(y, x); + mutt_window_move(MuttSidebarWindow, row, col); } /** -- 2.40.0