1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Allow alt-num to select window

This commit is contained in:
James Booth 2012-11-24 01:57:24 +00:00
parent f7ad1c0335
commit d30d31b57d
4 changed files with 79 additions and 30 deletions

View File

@ -216,6 +216,12 @@ inp_put_back(void)
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
}
int
inp_get_next_char(void)
{
return wgetch(inp_win);
}
void
inp_replace_input(char *input, const char * const new_input, int *size)
{
@ -242,6 +248,7 @@ _handle_edit(const int ch, char *input, int *size)
char *next = NULL;
int inp_y = 0;
int inp_x = 0;
int next_ch;
getmaxyx(stdscr, rows, cols);
getyx(inp_win, inp_y, inp_x);
@ -249,9 +256,50 @@ _handle_edit(const int ch, char *input, int *size)
switch(ch) {
case 27: // ESC
*size = 0;
inp_clear();
return 1;
// check for ALT-num
next_ch = inp_get_next_char();
if (next_ch != ERR) {
switch (next_ch)
{
case '1':
win_switch_if_active(0);
break;
case '2':
win_switch_if_active(1);
break;
case '3':
win_switch_if_active(2);
break;
case '4':
win_switch_if_active(3);
break;
case '5':
win_switch_if_active(4);
break;
case '6':
win_switch_if_active(5);
break;
case '7':
win_switch_if_active(6);
break;
case '8':
win_switch_if_active(7);
break;
case '9':
win_switch_if_active(8);
break;
case '0':
win_switch_if_active(9);
break;
default:
break;
}
return 1;
} else {
*size = 0;
inp_clear();
return 1;
}
case 127:
case KEY_BACKSPACE:

View File

@ -37,7 +37,7 @@
static WINDOW *status_bar;
static char *message = NULL;
static char _active[29] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ]";
static char _active[29] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ]";
static int is_active[9];
static int is_new[9];
static int dirty;
@ -59,7 +59,7 @@ create_status_bar(void)
status_bar = newwin(1, cols, rows-2, 0);
wbkgd(status_bar, COLOUR_STATUS_TEXT);
wattron(status_bar, COLOUR_STATUS_BRACKET);
mvwprintw(status_bar, 0, cols - 29, _active);
mvwprintw(status_bar, 0, cols - 28, _active);
wattroff(status_bar, COLOUR_STATUS_BRACKET);
last_time = g_date_time_new_now_local();
@ -99,7 +99,7 @@ status_bar_resize(void)
wbkgd(status_bar, COLOUR_STATUS_TEXT);
wclear(status_bar);
wattron(status_bar, COLOUR_STATUS_BRACKET);
mvwprintw(status_bar, 0, cols - 29, _active);
mvwprintw(status_bar, 0, cols - 28, _active);
wattroff(status_bar, COLOUR_STATUS_BRACKET);
for(i = 0; i < 9; i++) {
@ -126,9 +126,9 @@ status_bar_inactive(const int win)
int cols = getmaxx(stdscr);
mvwaddch(status_bar, 0, cols - 29 + active_pos, ' ');
mvwaddch(status_bar, 0, cols - 28 + active_pos, ' ');
if (win == 9)
mvwaddch(status_bar, 0, cols - 29 + active_pos + 1, ' ');
mvwaddch(status_bar, 0, cols - 28 + active_pos + 1, ' ');
dirty = TRUE;
}
@ -145,9 +145,9 @@ status_bar_active(const int win)
wattron(status_bar, COLOUR_STATUS_ACTIVE);
if (win < 9)
mvwprintw(status_bar, 0, cols - 29 + active_pos, "%d", win+1);
mvwprintw(status_bar, 0, cols - 28 + active_pos, "%d", win+1);
else
mvwprintw(status_bar, 0, cols - 29 + active_pos, "10");
mvwprintw(status_bar, 0, cols - 28 + active_pos, "0");
wattroff(status_bar, COLOUR_STATUS_ACTIVE);
dirty = TRUE;
@ -166,9 +166,9 @@ status_bar_new(const int win)
wattron(status_bar, COLOUR_STATUS_NEW);
wattron(status_bar, A_BLINK);
if (win < 9)
mvwprintw(status_bar, 0, cols - 29 + active_pos, "%d", win+1);
mvwprintw(status_bar, 0, cols - 28 + active_pos, "%d", win+1);
else
mvwprintw(status_bar, 0, cols - 29 + active_pos, "10");
mvwprintw(status_bar, 0, cols - 28 + active_pos, "0");
wattroff(status_bar, COLOUR_STATUS_NEW);
wattroff(status_bar, A_BLINK);
@ -199,7 +199,7 @@ status_bar_print_message(const char * const msg)
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_BRACKET);
mvwprintw(status_bar, 0, cols - 29, _active);
mvwprintw(status_bar, 0, cols - 28, _active);
wattroff(status_bar, COLOUR_STATUS_BRACKET);
int i;
@ -232,7 +232,7 @@ status_bar_clear(void)
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_BRACKET);
mvwprintw(status_bar, 0, cols - 29, _active);
mvwprintw(status_bar, 0, cols - 28, _active);
wattroff(status_bar, COLOUR_STATUS_BRACKET);
dirty = TRUE;
@ -251,7 +251,7 @@ status_bar_clear_message(void)
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_STATUS_BRACKET);
mvwprintw(status_bar, 0, cols - 29, _active);
mvwprintw(status_bar, 0, cols - 28, _active);
wattroff(status_bar, COLOUR_STATUS_BRACKET);
int i;

View File

@ -103,6 +103,7 @@ void win_bad_show(const char * const msg);
void win_remind(void);
void win_activity(void);
void win_no_activity(void);
void win_switch_if_active(const int i);
void win_join_chat(const char * const room, const char * const nick);
void win_show_room_roster(const char * const room);
@ -166,5 +167,6 @@ void inp_non_block(void);
void inp_block(void);
void inp_get_password(char *passwd);
void inp_replace_input(char *input, const char * const new_input, int *size);
int inp_get_next_char(void);
#endif

View File

@ -74,7 +74,6 @@ static void _cons_show_contact(PContact contact);
static int _find_prof_win_index(const char * const contact);
static int _new_prof_win(const char * const contact, win_type_t type);
static void _current_window_refresh(void);
static void _win_switch_if_active(const int i);
static void _win_show_time(WINDOW *win);
static void _win_show_user(WINDOW *win, const char * const user, const int colour);
static void _win_show_message(WINDOW *win, const char * const message);
@ -644,7 +643,7 @@ win_show_outgoing_msg(const char * const from, const char * const to,
_win_show_user(win, from, 0);
_win_show_message(win, message);
}
_win_switch_if_active(win_index);
win_switch_if_active(win_index);
}
void
@ -657,7 +656,7 @@ win_join_chat(const char * const room, const char * const nick)
win_index = _new_prof_win(room, WIN_MUC);
}
_win_switch_if_active(win_index);
win_switch_if_active(win_index);
}
void
@ -1467,8 +1466,8 @@ _new_prof_win(const char * const contact, win_type_t type)
return i;
}
static void
_win_switch_if_active(const int i)
void
win_switch_if_active(const int i)
{
win_page_off();
if (windows[i] != NULL) {
@ -1695,25 +1694,25 @@ static void
_win_handle_switch(const int * const ch)
{
if (*ch == KEY_F(1)) {
_win_switch_if_active(0);
win_switch_if_active(0);
} else if (*ch == KEY_F(2)) {
_win_switch_if_active(1);
win_switch_if_active(1);
} else if (*ch == KEY_F(3)) {
_win_switch_if_active(2);
win_switch_if_active(2);
} else if (*ch == KEY_F(4)) {
_win_switch_if_active(3);
win_switch_if_active(3);
} else if (*ch == KEY_F(5)) {
_win_switch_if_active(4);
win_switch_if_active(4);
} else if (*ch == KEY_F(6)) {
_win_switch_if_active(5);
win_switch_if_active(5);
} else if (*ch == KEY_F(7)) {
_win_switch_if_active(6);
win_switch_if_active(6);
} else if (*ch == KEY_F(8)) {
_win_switch_if_active(7);
win_switch_if_active(7);
} else if (*ch == KEY_F(9)) {
_win_switch_if_active(8);
win_switch_if_active(8);
} else if (*ch == KEY_F(10)) {
_win_switch_if_active(9);
win_switch_if_active(9);
}
}