From b8ba9b038c668dd7576fcf1855cfa3f404924ca3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 7 Oct 2014 21:12:19 +0100 Subject: [PATCH] Added scroll support to occupant list --- src/profanity.c | 5 +++-- src/server_events.c | 3 --- src/ui/core.c | 40 ++++++++++++++++++++++++++++++++++------ src/ui/inputwin.c | 14 +++++++------- src/ui/inputwin.h | 2 +- src/ui/ui.h | 4 ++-- src/ui/window.c | 4 ++-- src/ui/window.h | 1 + src/ui/windows.c | 2 +- 9 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index c8e55201..497be90a 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -97,6 +97,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name) while(cmd_result == TRUE) { wint_t ch = ERR; + int result; size = 0; while(ch != '\n') { @@ -113,14 +114,14 @@ prof_run(const int disable_tls, char *log_level, char *account_name) g_timer_start(timer); } - ui_handle_special_keys(&ch, inp, size); + ui_handle_special_keys(&ch, result, inp, size); #ifdef HAVE_LIBOTR otr_poll(); #endif jabber_process_events(); ui_update(); - ch = ui_get_char(inp, &size); + ch = ui_get_char(inp, &size, &result); } inp[size++] = '\0'; diff --git a/src/server_events.c b/src/server_events.c index 7dbf30af..6dce3e78 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -693,9 +693,6 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea muc_invites_remove(room); muc_roster_set_complete(room); - GList *roster = muc_roster(room); - ui_room_roster(room, roster, NULL); - char *subject = muc_subject(room); if (subject != NULL) { ui_room_subject(room, NULL, subject); diff --git a/src/ui/core.c b/src/ui/core.c index 6cac05b9..935c242c 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -80,7 +80,7 @@ static Display *display; static GTimer *ui_idle_time; static void _win_handle_switch(const wint_t * const ch); -static void _win_handle_page(const wint_t * const ch); +static void _win_handle_page(const wint_t * const ch, const int result); static void _win_show_history(WINDOW *win, int win_index, const char * const contact); static void _ui_draw_term_title(void); @@ -175,9 +175,9 @@ _ui_close(void) } static wint_t -_ui_get_char(char *input, int *size) +_ui_get_char(char *input, int *size, int *result) { - wint_t ch = inp_get_char(input, size); + wint_t ch = inp_get_char(input, size, result); if (ch != ERR) { ui_reset_idle_time(); } @@ -585,11 +585,11 @@ _ui_disconnected(void) } static void -_ui_handle_special_keys(const wint_t * const ch, const char * const inp, +_ui_handle_special_keys(const wint_t * const ch, const int result, const char * const inp, const int size) { _win_handle_switch(ch); - _win_handle_page(ch); + _win_handle_page(ch, result); if (*ch == KEY_RESIZE) { ui_resize(*ch, inp, size); } @@ -2806,11 +2806,12 @@ _win_handle_switch(const wint_t * const ch) } static void -_win_handle_page(const wint_t * const ch) +_win_handle_page(const wint_t * const ch, const int result) { ProfWin *current = wins_get_current(); int rows = getmaxy(stdscr); int y = getcury(current->win); + int sub_y = getcury(current->subwin); int page_space = rows - 4; int *page_start = &(current->y_pos); @@ -2883,6 +2884,33 @@ _win_handle_page(const wint_t * const ch) if ((y) - *page_start == page_space) { current->paged = 0; } + + if (current->type == WIN_MUC) { + // alt up arrow + if ((result == KEY_CODE_YES) && (*ch == 565)) { + current->sub_y_pos -= page_space; + + // went past beginning, show first page + if (current->sub_y_pos < 0) + current->sub_y_pos = 0; + + win_update_virtual(current); + + // alt down arrow + } else if ((result == KEY_CODE_YES) && (*ch == 524)) { + current->sub_y_pos += page_space; + + // only got half a screen, show full screen + if ((sub_y- (current->sub_y_pos)) < page_space) + current->sub_y_pos = sub_y - page_space; + + // went past end, show full screen + else if (current->sub_y_pos >= sub_y) + current->sub_y_pos = sub_y - page_space - 1; + + win_update_virtual(current); + } + } } static void diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 8bebfce8..153361a6 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -120,7 +120,7 @@ inp_block(void) } wint_t -inp_get_char(char *input, int *size) +inp_get_char(char *input, int *size, int *result) { wint_t ch; int display_size = 0; @@ -131,7 +131,7 @@ inp_get_char(char *input, int *size) // echo off, and get some more input noecho(); - int result = wget_wch(inp_win, &ch); + *result = wget_wch(inp_win, &ch); gboolean in_command = FALSE; if ((display_size > 0 && input[0] == '/') || @@ -140,12 +140,12 @@ inp_get_char(char *input, int *size) } if (prefs_get_boolean(PREF_STATES)) { - if (result == ERR) { + if (*result == ERR) { prof_handle_idle(); } if (prefs_get_boolean(PREF_OUTTYPE) - && (result != ERR) - && (result != KEY_CODE_YES) + && (*result != ERR) + && (*result != KEY_CODE_YES) && !in_command && _printable(ch)) { prof_handle_activity(); @@ -153,8 +153,8 @@ inp_get_char(char *input, int *size) } // if it wasn't an arrow key etc - if (!_handle_edit(result, ch, input, size)) { - if (_printable(ch) && result != KEY_CODE_YES) { + if (!_handle_edit(*result, ch, input, size)) { + if (_printable(ch) && *result != KEY_CODE_YES) { if (*size >= INP_WIN_MAX) { return ERR; } diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index c351f81b..85c75c8e 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -36,7 +36,7 @@ #define UI_INPUTWIN_H void create_input_window(void); -wint_t inp_get_char(char *input, int *size); +wint_t inp_get_char(char *input, int *size, int *result); void inp_win_reset(void); void inp_win_resize(const char * input, const int size); void inp_put_back(void); diff --git a/src/ui/ui.h b/src/ui/ui.h index f6fad254..e0193854 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -66,7 +66,7 @@ void (*ui_close)(void); void (*ui_resize)(const int ch, const char * const input, const int size); GSList* (*ui_get_recipients)(void); -void (*ui_handle_special_keys)(const wint_t * const ch, const char * const inp, +void (*ui_handle_special_keys)(const wint_t * const ch, const int result, const char * const inp, const int size); gboolean (*ui_switch_win)(const int i); void (*ui_next_win)(void); @@ -223,7 +223,7 @@ void (*ui_update_presence)(const resource_presence_t resource_presence, void (*ui_about)(void); void (*ui_statusbar_new)(const int win); -wint_t (*ui_get_char)(char *input, int *size); +wint_t (*ui_get_char)(char *input, int *size, int *result); void (*ui_input_clear)(void); void (*ui_input_nonblocking)(void); void (*ui_replace_input)(char *input, const char * const new_input, int *size); diff --git a/src/ui/window.c b/src/ui/window.c index 03ed18e1..34c5e934 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -65,7 +65,6 @@ win_create(const char * const title, int cols, win_type_t type) wbkgd(new_win->win, COLOUR_TEXT); new_win->subwin = newpad(PAD_SIZE, cols/OCCUPANT_WIN_SIZE); - wvline(new_win->subwin, 0, 0); wbkgd(new_win->subwin, COLOUR_TEXT); } else { new_win->win = newpad(PAD_SIZE, (cols)); @@ -76,6 +75,7 @@ win_create(const char * const title, int cols, win_type_t type) new_win->buffer = buffer_create(); new_win->y_pos = 0; + new_win->sub_y_pos = 0; new_win->paged = 0; new_win->unread = 0; new_win->history_shown = 0; @@ -109,7 +109,7 @@ win_update_virtual(ProfWin *window) if (window->type == WIN_MUC) { pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, ((cols/OCCUPANT_WIN_SIZE) * (OCCUPANT_WIN_SIZE-1)) -1); - pnoutrefresh(window->subwin, 0, 0, 1, (cols/OCCUPANT_WIN_SIZE) * (OCCUPANT_WIN_SIZE-1), rows-3, cols-1); + pnoutrefresh(window->subwin, window->sub_y_pos, 0, 1, (cols/OCCUPANT_WIN_SIZE) * (OCCUPANT_WIN_SIZE-1), rows-3, cols-1); } else { pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1); } diff --git a/src/ui/window.h b/src/ui/window.h index 196578d8..02045305 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -75,6 +75,7 @@ typedef struct prof_win_t { gboolean is_otr; gboolean is_trusted; int y_pos; + int sub_y_pos; int paged; int unread; int history_shown; diff --git a/src/ui/windows.c b/src/ui/windows.c index 3f636fdb..220b84f8 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -307,7 +307,7 @@ wins_resize_all(void) ProfWin *current_win = wins_get_current(); if (current_win->type == WIN_MUC) { pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, ((cols/OCCUPANT_WIN_SIZE) * (OCCUPANT_WIN_SIZE-1)) -1); - pnoutrefresh(current_win->subwin, 0, 0, 1, (cols/OCCUPANT_WIN_SIZE) * (OCCUPANT_WIN_SIZE-1), rows-3, cols-1); + pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, (cols/OCCUPANT_WIN_SIZE) * (OCCUPANT_WIN_SIZE-1), rows-3, cols-1); } else { pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, cols-1); }