mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Tidied special key functions
This commit is contained in:
parent
3d8b1a5a4c
commit
4f82ece2d3
@ -76,7 +76,7 @@ void inp_block(void)
|
||||
wtimeout(inp_win, -1);
|
||||
}
|
||||
|
||||
void inp_poll_char(int *ch, char *input, int *size)
|
||||
void inp_get_char(int *ch, char *input, int *size)
|
||||
{
|
||||
int inp_y = 0;
|
||||
int inp_x = 0;
|
||||
|
@ -47,9 +47,8 @@ void profanity_run(void)
|
||||
while(ch != '\n') {
|
||||
gui_refresh();
|
||||
jabber_process_events();
|
||||
win_handle_switch(&ch);
|
||||
win_handle_page(&ch);
|
||||
inp_poll_char(&ch, inp, &size);
|
||||
win_handle_special_keys(&ch);
|
||||
inp_get_char(&ch, inp, &size);
|
||||
}
|
||||
|
||||
inp[size++] = '\0';
|
||||
|
126
windows.c
126
windows.c
@ -55,6 +55,8 @@ static void _show_status_string(WINDOW *win, const char * const from,
|
||||
const char * const default_show);
|
||||
static void _cons_show_incoming_message(const char * const short_from,
|
||||
const int win_index);
|
||||
static void _win_handle_switch(const int * const ch);
|
||||
static void _win_handle_page(const int * const ch);
|
||||
|
||||
void gui_init(void)
|
||||
{
|
||||
@ -302,29 +304,10 @@ void cons_bad_message(void)
|
||||
cons_show("Usage: /msg user@host message");
|
||||
}
|
||||
|
||||
void win_handle_switch(const int * const ch)
|
||||
void win_handle_special_keys(const int * const ch)
|
||||
{
|
||||
if (*ch == KEY_F(1)) {
|
||||
_win_switch_if_active(0);
|
||||
} else if (*ch == KEY_F(2)) {
|
||||
_win_switch_if_active(1);
|
||||
} else if (*ch == KEY_F(3)) {
|
||||
_win_switch_if_active(2);
|
||||
} else if (*ch == KEY_F(4)) {
|
||||
_win_switch_if_active(3);
|
||||
} else if (*ch == KEY_F(5)) {
|
||||
_win_switch_if_active(4);
|
||||
} else if (*ch == KEY_F(6)) {
|
||||
_win_switch_if_active(5);
|
||||
} else if (*ch == KEY_F(7)) {
|
||||
_win_switch_if_active(6);
|
||||
} else if (*ch == KEY_F(8)) {
|
||||
_win_switch_if_active(7);
|
||||
} else if (*ch == KEY_F(9)) {
|
||||
_win_switch_if_active(8);
|
||||
} else if (*ch == KEY_F(10)) {
|
||||
_win_switch_if_active(9);
|
||||
}
|
||||
_win_handle_switch(ch);
|
||||
_win_handle_page(ch);
|
||||
}
|
||||
|
||||
void win_page_off(void)
|
||||
@ -345,43 +328,6 @@ void win_page_off(void)
|
||||
dirty = TRUE;
|
||||
}
|
||||
|
||||
void win_handle_page(const int * const ch)
|
||||
{
|
||||
int rows, cols, y, x;
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
getyx(_wins[_curr_prof_win].win, y, x);
|
||||
|
||||
int page_space = rows - 4;
|
||||
int *page_start = &_wins[_curr_prof_win].y_pos;
|
||||
|
||||
// page up
|
||||
if (*ch == KEY_PPAGE) {
|
||||
*page_start -= page_space;
|
||||
|
||||
// went past beginning, show first page
|
||||
if (*page_start < 0)
|
||||
*page_start = 0;
|
||||
|
||||
_wins[_curr_prof_win].paged = 1;
|
||||
dirty = TRUE;
|
||||
|
||||
// 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;
|
||||
|
||||
_wins[_curr_prof_win].paged = 1;
|
||||
dirty = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static void _create_windows(void)
|
||||
{
|
||||
int rows, cols;
|
||||
@ -533,3 +479,65 @@ static void _cons_show_incoming_message(const char * const short_from, const int
|
||||
wattroff(_cons_win, COLOR_PAIR(8));
|
||||
}
|
||||
|
||||
static void _win_handle_switch(const int * const ch)
|
||||
{
|
||||
if (*ch == KEY_F(1)) {
|
||||
_win_switch_if_active(0);
|
||||
} else if (*ch == KEY_F(2)) {
|
||||
_win_switch_if_active(1);
|
||||
} else if (*ch == KEY_F(3)) {
|
||||
_win_switch_if_active(2);
|
||||
} else if (*ch == KEY_F(4)) {
|
||||
_win_switch_if_active(3);
|
||||
} else if (*ch == KEY_F(5)) {
|
||||
_win_switch_if_active(4);
|
||||
} else if (*ch == KEY_F(6)) {
|
||||
_win_switch_if_active(5);
|
||||
} else if (*ch == KEY_F(7)) {
|
||||
_win_switch_if_active(6);
|
||||
} else if (*ch == KEY_F(8)) {
|
||||
_win_switch_if_active(7);
|
||||
} else if (*ch == KEY_F(9)) {
|
||||
_win_switch_if_active(8);
|
||||
} else if (*ch == KEY_F(10)) {
|
||||
_win_switch_if_active(9);
|
||||
}
|
||||
}
|
||||
|
||||
static void _win_handle_page(const int * const ch)
|
||||
{
|
||||
int rows, cols, y, x;
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
getyx(_wins[_curr_prof_win].win, y, x);
|
||||
|
||||
int page_space = rows - 4;
|
||||
int *page_start = &_wins[_curr_prof_win].y_pos;
|
||||
|
||||
// page up
|
||||
if (*ch == KEY_PPAGE) {
|
||||
*page_start -= page_space;
|
||||
|
||||
// went past beginning, show first page
|
||||
if (*page_start < 0)
|
||||
*page_start = 0;
|
||||
|
||||
_wins[_curr_prof_win].paged = 1;
|
||||
dirty = TRUE;
|
||||
|
||||
// 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;
|
||||
|
||||
_wins[_curr_prof_win].paged = 1;
|
||||
dirty = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,8 +57,7 @@ char *win_get_recipient(void);
|
||||
void win_show_incomming_msg(const char * const from, const char * const message);
|
||||
void win_show_outgoing_msg(const char * const from, const char * const to,
|
||||
const char * const message);
|
||||
void win_handle_switch(const int * const ch);
|
||||
void win_handle_page(const int * const ch);
|
||||
void win_handle_special_keys(const int * const ch);
|
||||
void win_page_off(void);
|
||||
void win_contact_online(const char * const from, const char * const show,
|
||||
const char * const status);
|
||||
@ -87,7 +86,7 @@ void status_bar_active(const int win);
|
||||
void status_bar_update_time(void);
|
||||
|
||||
// input window actions
|
||||
void inp_poll_char(int *ch, char *input, int *size);
|
||||
void inp_get_char(int *ch, char *input, int *size);
|
||||
void inp_clear(void);
|
||||
void inp_put_back(void);
|
||||
void inp_non_block(void);
|
||||
|
Loading…
Reference in New Issue
Block a user