1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added paging handlers

This commit is contained in:
James Booth 2015-01-31 22:00:22 +00:00
parent e6f27de552
commit 28dd545877
5 changed files with 279 additions and 69 deletions

View File

@ -208,6 +208,34 @@ ui_readline(void)
// return line;
}
void
ui_page_up(void)
{
ProfWin *current = wins_get_current();
win_page_up(current);
}
void
ui_page_down(void)
{
ProfWin *current = wins_get_current();
win_page_down(current);
}
void
ui_subwin_page_up(void)
{
ProfWin *current = wins_get_current();
win_sub_page_up(current);
}
void
ui_subwin_page_down(void)
{
ProfWin *current = wins_get_current();
win_sub_page_down(current);
}
void
ui_input_clear(void)
{

View File

@ -88,6 +88,12 @@ cb_linehandler(char *line)
free(line);
}
void
resize_signal_handler(int signal)
{
ui_resize();
}
int
tab_handler(int count, int key)
{
@ -114,10 +120,144 @@ tab_handler(int count, int key)
return 0;
}
void
resize_signal_handler(int signal)
int
alt1_handler(int count, int key)
{
ui_resize();
ui_switch_win(1);
return 0;
}
int
alt2_handler(int count, int key)
{
ui_switch_win(2);
return 0;
}
int
alt3_handler(int count, int key)
{
ui_switch_win(3);
return 0;
}
int
alt4_handler(int count, int key)
{
ui_switch_win(4);
return 0;
}
int
alt5_handler(int count, int key)
{
ui_switch_win(5);
return 0;
}
int
alt6_handler(int count, int key)
{
ui_switch_win(6);
return 0;
}
int
alt7_handler(int count, int key)
{
ui_switch_win(7);
return 0;
}
int
alt8_handler(int count, int key)
{
ui_switch_win(8);
return 0;
}
int
alt9_handler(int count, int key)
{
ui_switch_win(9);
return 0;
}
int
alt0_handler(int count, int key)
{
ui_switch_win(0);
return 0;
}
int
altleft_handler(int count, int key)
{
ui_previous_win();
return 0;
}
int
altright_handler(int count, int key)
{
ui_next_win();
return 0;
}
int
pageup_handler(int count, int key)
{
ui_page_up();
return 0;
}
int
pagedown_handler(int count, int key)
{
ui_page_down();
return 0;
}
int
altpageup_handler(int count, int key)
{
ui_subwin_page_up();
return 0;
}
int
altpagedown_handler(int count, int key)
{
ui_subwin_page_down();
return 0;
}
int
startup_hook(void)
{
rl_bind_keyseq("\\e1", alt1_handler);
rl_bind_keyseq("\\e2", alt2_handler);
rl_bind_keyseq("\\e3", alt3_handler);
rl_bind_keyseq("\\e4", alt4_handler);
rl_bind_keyseq("\\e5", alt5_handler);
rl_bind_keyseq("\\e6", alt6_handler);
rl_bind_keyseq("\\e7", alt7_handler);
rl_bind_keyseq("\\e8", alt8_handler);
rl_bind_keyseq("\\e9", alt9_handler);
rl_bind_keyseq("\\e0", alt0_handler);
rl_bind_keyseq("\\e[1;3D", altleft_handler);
rl_bind_keyseq("\\e[1;3C", altright_handler);
rl_bind_keyseq("\\e[5~", pageup_handler);
rl_bind_keyseq("\\e[6~", pagedown_handler);
rl_bind_keyseq("\\e[5;3~", altpageup_handler);
rl_bind_keyseq("\\e[6;3~", altpagedown_handler);
rl_bind_key('\t', tab_handler);
return 0;
}
void
@ -130,8 +270,8 @@ create_input_window(void)
#endif
p_rl_timeout.tv_sec = 0;
p_rl_timeout.tv_usec = inp_timeout * 1000;
rl_startup_hook = startup_hook;
rl_callback_handler_install(NULL, cb_linehandler);
rl_bind_key('\t', tab_handler);
signal(SIGWINCH, resize_signal_handler);
@ -140,6 +280,7 @@ create_input_window(void)
keypad(inp_win, TRUE);
wmove(inp_win, 0, 0);
_inp_win_update_virtual();
}

View File

@ -218,6 +218,11 @@ void ui_tidy_wins(void);
void ui_prune_wins(void);
gboolean ui_swap_wins(int source_win, int target_win);
void ui_page_up(void);
void ui_page_down(void);
void ui_subwin_page_up(void);
void ui_subwin_page_down(void);
void ui_auto_away(void);
void ui_end_auto_away(void);
void ui_titlebar_presence(contact_presence_t presence);

View File

@ -358,7 +358,101 @@ win_free(ProfWin* window)
}
void
win_handle_page(ProfWin *window, const wint_t ch, const int result)
win_page_up(ProfWin *window)
{
int rows = getmaxy(stdscr);
int y = getcury(window->layout->win);
int page_space = rows - 4;
int *page_start = &(window->layout->y_pos);
*page_start -= page_space;
// went past beginning, show first page
if (*page_start < 0)
*page_start = 0;
window->layout->paged = 1;
win_update_virtual(window);
// switch off page if last line and space line visible
if ((y) - *page_start == page_space) {
window->layout->paged = 0;
}
}
void
win_page_down(ProfWin *window)
{
int rows = getmaxy(stdscr);
int y = getcury(window->layout->win);
int page_space = rows - 4;
int *page_start = &(window->layout->y_pos);
*page_start += page_space;
// only got half a screen, show full screen
if ((y - (*page_start)) < page_space)
*page_start = y - page_space;
// went past end, show full screen
else if (*page_start >= y)
*page_start = y - page_space - 1;
window->layout->paged = 1;
win_update_virtual(window);
// switch off page if last line and space line visible
if ((y) - *page_start == page_space) {
window->layout->paged = 0;
}
}
void
win_sub_page_down(ProfWin *window)
{
if (window->layout->type == LAYOUT_SPLIT) {
int rows = getmaxy(stdscr);
int page_space = rows - 4;
ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
int sub_y = getcury(split_layout->subwin);
int *sub_y_pos = &(split_layout->sub_y_pos);
*sub_y_pos += page_space;
// only got half a screen, show full screen
if ((sub_y- (*sub_y_pos)) < page_space)
*sub_y_pos = sub_y - page_space;
// went past end, show full screen
else if (*sub_y_pos >= sub_y)
*sub_y_pos = sub_y - page_space - 1;
win_update_virtual(window);
}
}
void
win_sub_page_up(ProfWin *window)
{
if (window->layout->type == LAYOUT_SPLIT) {
int rows = getmaxy(stdscr);
int page_space = rows - 4;
ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
int *sub_y_pos = &(split_layout->sub_y_pos);
*sub_y_pos -= page_space;
// went past beginning, show first page
if (*sub_y_pos < 0)
*sub_y_pos = 0;
win_update_virtual(window);
}
}
void
win_mouse(ProfWin *window, const wint_t ch, const int result)
{
int rows = getmaxy(stdscr);
int y = getcury(window->layout->win);
@ -402,69 +496,6 @@ win_handle_page(ProfWin *window, const wint_t ch, const int result)
}
}
}
// page up
if (ch == KEY_PPAGE) {
*page_start -= page_space;
// went past beginning, show first page
if (*page_start < 0)
*page_start = 0;
window->layout->paged = 1;
win_update_virtual(window);
// page down
} else if (ch == KEY_NPAGE) {
*page_start += page_space;
// only got half a screen, show full screen
if ((y - (*page_start)) < page_space)
*page_start = y - page_space;
// went past end, show full screen
else if (*page_start >= y)
*page_start = y - page_space - 1;
window->layout->paged = 1;
win_update_virtual(window);
}
// switch off page if last line and space line visible
if ((y) - *page_start == page_space) {
window->layout->paged = 0;
}
if (window->layout->type == LAYOUT_SPLIT) {
ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
int sub_y = getcury(split_layout->subwin);
int *sub_y_pos = &(split_layout->sub_y_pos);
// alt up arrow
if ((result == KEY_CODE_YES) && ((ch == 565) || (ch == 337))) {
*sub_y_pos -= page_space;
// went past beginning, show first page
if (*sub_y_pos < 0)
*sub_y_pos = 0;
win_update_virtual(window);
// alt down arrow
} else if ((result == KEY_CODE_YES) && ((ch == 524) || (ch == 336))) {
*sub_y_pos += page_space;
// only got half a screen, show full screen
if ((sub_y- (*sub_y_pos)) < page_space)
*sub_y_pos = sub_y - page_space;
// went past end, show full screen
else if (*sub_y_pos >= sub_y)
*sub_y_pos = sub_y - page_space - 1;
win_update_virtual(window);
}
}
}
void

View File

@ -178,9 +178,14 @@ void win_show_subwin(ProfWin *window);
int win_roster_cols(void);
int win_occpuants_cols(void);
void win_printline_nowrap(WINDOW *win, char *msg);
void win_handle_page(ProfWin *current, const wint_t ch, const int result);
void win_mouse(ProfWin *current, const wint_t ch, const int result);
int win_unread(ProfWin *window);
gboolean win_has_active_subwin(ProfWin *window);
void win_page_up(ProfWin *window);
void win_page_down(ProfWin *window);
void win_sub_page_down(ProfWin *window);
void win_sub_page_up(ProfWin *window);
#endif