diff options
author | James Booth <boothj5@gmail.com> | 2012-04-17 22:43:35 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-04-17 22:43:35 +0100 |
commit | 32e025f5cdc0753c970410fc7fe44edc38fd1225 (patch) | |
tree | d7f44a861394aab91cdc36dda0a997d15f1973e7 | |
parent | 84c864663b7217631abbebad3ef8f7c85be9fc88 (diff) | |
download | profani-tty-32e025f5cdc0753c970410fc7fe44edc38fd1225.tar.gz |
Moved resize code to windows.c, reorder main loop
-rw-r--r-- | input_win.c | 50 | ||||
-rw-r--r-- | profanity.c | 2 | ||||
-rw-r--r-- | windows.c | 22 | ||||
-rw-r--r-- | windows.h | 1 |
4 files changed, 37 insertions, 38 deletions
diff --git a/input_win.c b/input_win.c index 5c07eff9..51e5552d 100644 --- a/input_win.c +++ b/input_win.c @@ -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); - - for (i = *size; i > inp_x -1; i--) - input[i] = input[i-1]; - input[inp_x -1] = *ch; - - (*size)++; - - // otherwise just append - } else { - waddch(inp_win, *ch); - input[(*size)++] = *ch; - } - - reset_search_attempts(); + // 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; + + (*size)++; + + // 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) diff --git a/profanity.c b/profanity.c index e5318a68..ab50d4fd 100644 --- a/profanity.c +++ b/profanity.c @@ -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'; diff --git a/windows.c b/windows.c index 1c52113b..37f94053 100644 --- a/windows.c +++ b/windows.c @@ -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; diff --git a/windows.h b/windows.h index 01be6951..de72a23e 100644 --- a/windows.h +++ b/windows.h @@ -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); |