1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Moved resize code to windows.c, reorder main loop

This commit is contained in:
James Booth 2012-04-17 22:43:35 +01:00
parent 84c864663b
commit 32e025f5cd
4 changed files with 34 additions and 35 deletions

View File

@ -87,33 +87,29 @@ void inp_get_char(int *ch, char *input, int *size)
noecho();
*ch = wgetch(inp_win);
if (*ch == KEY_RESIZE) {
win_resize();
} else {
// if it wasn't an arrow key etc
if (!_handle_edit(*ch, input, size)) {
if (_printable(*ch)) {
getyx(inp_win, inp_y, inp_x);
// handle insert if not at end of input
if (inp_x <= *size) {
winsch(inp_win, *ch);
wmove(inp_win, inp_y, inp_x+1);
// if it wasn't an arrow key etc
if (!_handle_edit(*ch, input, size)) {
if (_printable(*ch)) {
getyx(inp_win, inp_y, inp_x);
// handle insert if not at end of input
if (inp_x <= *size) {
winsch(inp_win, *ch);
wmove(inp_win, inp_y, inp_x+1);
for (i = *size; i > inp_x -1; i--)
input[i] = input[i-1];
input[inp_x -1] = *ch;
for (i = *size; i > inp_x -1; i--)
input[i] = input[i-1];
input[inp_x -1] = *ch;
(*size)++;
(*size)++;
// otherwise just append
} else {
waddch(inp_win, *ch);
input[(*size)++] = *ch;
}
reset_search_attempts();
// otherwise just append
} else {
waddch(inp_win, *ch);
input[(*size)++] = *ch;
}
reset_search_attempts();
}
}
@ -254,7 +250,7 @@ static int _printable(const int ch)
ch != KEY_F(4) && ch != KEY_F(5) && ch != KEY_F(6) &&
ch != KEY_F(7) && ch != KEY_F(8) && ch != KEY_F(9) &&
ch != KEY_F(10) && ch!= KEY_F(11) && ch != KEY_F(12) &&
ch != KEY_IC && ch != KEY_EIC);
ch != KEY_IC && ch != KEY_EIC && ch != KEY_RESIZE);
}
static void _replace_input(char *input, const char * const new_input, int *size)

View File

@ -47,8 +47,8 @@ void profanity_run(void)
while(ch != '\n') {
gui_refresh();
jabber_process_events();
win_handle_special_keys(&ch);
inp_get_char(&ch, inp, &size);
win_handle_special_keys(&ch);
}
inp[size++] = '\0';

View File

@ -57,6 +57,7 @@ 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);
static void _win_handle_resize(const int * const ch);
void gui_init(void)
{
@ -88,15 +89,6 @@ void gui_init(void)
dirty = TRUE;
}
void win_resize(void)
{
create_title_bar();
create_status_bar();
create_input_window();
_current_window_refresh();
dirty = TRUE;
}
void gui_refresh(void)
{
title_bar_refresh();
@ -325,6 +317,7 @@ void win_handle_special_keys(const int * const ch)
{
_win_handle_switch(ch);
_win_handle_page(ch);
_win_handle_resize(ch);
}
void win_page_off(void)
@ -521,6 +514,17 @@ static void _win_handle_switch(const int * const ch)
}
}
static void _win_handle_resize(const int * const ch)
{
if (*ch == KEY_RESIZE) {
create_title_bar();
create_status_bar();
create_input_window();
_current_window_refresh();
dirty = TRUE;
}
}
static void _win_handle_page(const int * const ch)
{
int rows, cols, y, x;

View File

@ -37,7 +37,6 @@ struct prof_win {
void gui_init(void);
void gui_refresh(void);
void gui_close(void);
void win_resize(void);
// create windows
void create_title_bar(void);