reintroduce focus, as I ran out of keycodes for the input
This commit is contained in:
parent
9a90773210
commit
ec41ec2c87
@ -17,7 +17,8 @@ typedef struct {
|
||||
|
||||
extern ncdc_keybinding_t keys_guilds[];
|
||||
extern ncdc_keybinding_t keys_emacs[];
|
||||
extern ncdc_keybinding_t keys_mainwin[];
|
||||
extern ncdc_keybinding_t keys_chat[];
|
||||
extern ncdc_keybinding_t keys_global[];
|
||||
|
||||
ncdc_keybinding_t *ncdc_find_keybinding(ncdc_keybinding_t *keys,
|
||||
wchar_t const *key, size_t l);
|
||||
|
@ -23,6 +23,9 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n);
|
||||
|
||||
void ncdc_mainwindow_rightview(ncdc_mainwindow_t n);
|
||||
void ncdc_mainwindow_leftview(ncdc_mainwindow_t n);
|
||||
void ncdc_mainwindow_switch_guilds(ncdc_mainwindow_t n);
|
||||
void ncdc_mainwindow_switch_input(ncdc_mainwindow_t n);
|
||||
void ncdc_mainwindow_switch_chat(ncdc_mainwindow_t n);
|
||||
|
||||
void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n);
|
||||
|
||||
|
@ -56,7 +56,7 @@ extern void *mainwindow;
|
||||
|
||||
bool is_logged_in(void);
|
||||
|
||||
wchar_t *util_readkey(int esc, WINDOW *win);
|
||||
wchar_t *util_readkey(int esc);
|
||||
|
||||
void exit_main(void);
|
||||
|
||||
|
@ -23,35 +23,56 @@ ncdc_keybinding_t keys_guilds[] = {
|
||||
/* CTRL+KEY_UP
|
||||
*/
|
||||
NCDC_BINDING(L"\x1B[1;5A", L"previous-item", ncdc_treeview_previous),
|
||||
NCDC_BINDING(L"\x1BOA", L"previous-item", ncdc_treeview_previous),
|
||||
/* CTRL+KEY_DOWN
|
||||
*/
|
||||
NCDC_BINDING(L"\x1B[1;5B", L"next-item", ncdc_treeview_next),
|
||||
NCDC_BINDING(L"\x1BOB", L"next-item", ncdc_treeview_next),
|
||||
/* CTRL+KEY_RIGHT
|
||||
*/
|
||||
NCDC_BINDING(L"\x1B[1;5C", L"expand-item", ncdc_treeview_expand),
|
||||
NCDC_BINDING(L"\x1BOC", L"expand-item", ncdc_treeview_expand),
|
||||
/* CTRL+KEY_LEFT
|
||||
*/
|
||||
NCDC_BINDING(L"\x1B[1;5D", L"collapse-item", ncdc_treeview_collapse),
|
||||
NCDC_BINDING(L"\x1BOD", L"collapse-item", ncdc_treeview_collapse),
|
||||
NCDC_BINDEND()
|
||||
};
|
||||
|
||||
ncdc_keybinding_t keys_mainwin[] = {
|
||||
ncdc_keybinding_t keys_chat[] = {
|
||||
/* ALT+KEY_RIGHT
|
||||
*/
|
||||
NCDC_BINDING(L"\x1B[1;3C", L"right-window", ncdc_mainwindow_rightview),
|
||||
NCDC_BINDING(L"\x1B0C", L"right-window", ncdc_mainwindow_rightview),
|
||||
/* ALT+KEY_LEFT
|
||||
*/
|
||||
NCDC_BINDING(L"\x1B[1;3D", L"left-window", ncdc_mainwindow_leftview),
|
||||
NCDC_BINDING(L"\x1B0D", L"left-window", ncdc_mainwindow_leftview),
|
||||
|
||||
NCDC_BINDEND()
|
||||
};
|
||||
|
||||
ncdc_keybinding_t keys_global[] = {
|
||||
/* F1
|
||||
*/
|
||||
NCDC_BINDING(L"\x1BOP", L"select-input", ncdc_mainwindow_switch_input),
|
||||
/* F2
|
||||
*/
|
||||
NCDC_BINDING(L"\x1BOQ", L"select-guilds", ncdc_mainwindow_switch_guilds),
|
||||
/* F3
|
||||
*/
|
||||
NCDC_BINDING(L"\x1BOR", L"select-chat", ncdc_mainwindow_switch_chat),
|
||||
|
||||
NCDC_BINDEND()
|
||||
};
|
||||
|
||||
ncdc_keybinding_t keys_emacs[] = {
|
||||
/* key left
|
||||
*/
|
||||
NCDC_BINDCUR(KEY_LEFT, L"backward", ncdc_input_backward),
|
||||
NCDC_BINDING(L"\x1BOD", L"backward", ncdc_input_backward),
|
||||
/* key right
|
||||
*/
|
||||
NCDC_BINDCUR(KEY_RIGHT, L"forward", ncdc_input_forward),
|
||||
NCDC_BINDING(L"\x1BOC", L"forward", ncdc_input_forward),
|
||||
/* CTRL+F
|
||||
*/
|
||||
NCDC_BINDING(L"\x06", L"forward", ncdc_input_forward),
|
||||
@ -70,6 +91,8 @@ ncdc_keybinding_t keys_emacs[] = {
|
||||
/* CTRL+D
|
||||
*/
|
||||
NCDC_BINDING(L"\x04", L"delete", ncdc_input_delete),
|
||||
NCDC_BINDCUR(KEY_BACKSPACE, L"delete", ncdc_input_delete_backward),
|
||||
/* BACKSPACE
|
||||
*/
|
||||
NCDC_BINDING(L"\x7F", L"delete", ncdc_input_delete_backward),
|
||||
NCDC_BINDEND()
|
||||
};
|
||||
|
@ -184,14 +184,17 @@ static void ncdc_mainwindow_update_focus(ncdc_mainwindow_t n)
|
||||
switch (n->focus) {
|
||||
case FOCUS_GUILDS:
|
||||
{
|
||||
curs_set(0);
|
||||
} break;
|
||||
|
||||
case FOCUS_CHAT:
|
||||
{
|
||||
curs_set(0);
|
||||
} break;
|
||||
|
||||
case FOCUS_INPUT:
|
||||
{
|
||||
curs_set(1);
|
||||
wmove(n->input, 0, ncdc_input_cursor(n->in));
|
||||
wrefresh(n->input);
|
||||
} break;
|
||||
@ -343,26 +346,12 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n)
|
||||
wint_t i = 0;
|
||||
wchar_t *key = NULL;
|
||||
size_t keylen = 0;
|
||||
WINDOW *win = NULL;
|
||||
ncdc_keybinding_t *k = NULL;
|
||||
|
||||
switch (n->focus) {
|
||||
case FOCUS_INPUT: win = n->input; break;
|
||||
case FOCUS_CHAT: win = n->chat; break;
|
||||
case FOCUS_GUILDS: win = n->guilds; break;
|
||||
}
|
||||
|
||||
if (wget_wch(win, &i) == ERR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (i == KEY_RESIZE) {
|
||||
ncdc_mainwindow_resize(n);
|
||||
return;
|
||||
}
|
||||
i = fgetwc(stdin);
|
||||
|
||||
if (i == KEY_ESCAPE) {
|
||||
if ((key = util_readkey(i, n->input)) == NULL) {
|
||||
if ((key = util_readkey(i)) == NULL) {
|
||||
return;
|
||||
}
|
||||
keylen = wcslen(key);
|
||||
@ -379,17 +368,30 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n)
|
||||
fclose(f);
|
||||
|
||||
if (key != NULL &&
|
||||
(k = ncdc_find_keybinding(keys_mainwin, key, keylen)) != NULL) {
|
||||
(k = ncdc_find_keybinding(keys_global, key, keylen)) != NULL) {
|
||||
k->handler(n);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (n->focus) {
|
||||
case FOCUS_CHAT:
|
||||
{
|
||||
if (key != NULL &&
|
||||
(k = ncdc_find_keybinding(keys_chat, key, keylen)) != NULL) {
|
||||
k->handler(n->guildview);
|
||||
}
|
||||
} break;
|
||||
|
||||
case FOCUS_GUILDS:
|
||||
{
|
||||
if (key != NULL &&
|
||||
(k = ncdc_find_keybinding(keys_guilds, key, keylen)) != NULL) {
|
||||
k->handler(n->guildview);
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
|
||||
case FOCUS_INPUT:
|
||||
{
|
||||
if (n->focus == FOCUS_INPUT) {
|
||||
if (key == NULL) {
|
||||
ncdc_input_feed(n->in, (wchar_t const *)&i, 1);
|
||||
@ -397,6 +399,8 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n)
|
||||
ncdc_input_feed(n->in, key, wcslen(key));
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
free(key);
|
||||
}
|
||||
@ -469,6 +473,27 @@ static void ncdc_mainwindow_ack_view(ncdc_mainwindow_t n)
|
||||
#endif
|
||||
}
|
||||
|
||||
void ncdc_mainwindow_switch_guilds(ncdc_mainwindow_t n)
|
||||
{
|
||||
return_if_true(n == NULL,);
|
||||
n->focus = FOCUS_GUILDS;
|
||||
ncdc_mainwindow_update_focus(n);
|
||||
}
|
||||
|
||||
void ncdc_mainwindow_switch_input(ncdc_mainwindow_t n)
|
||||
{
|
||||
return_if_true(n == NULL,);
|
||||
n->focus = FOCUS_INPUT;
|
||||
ncdc_mainwindow_update_focus(n);
|
||||
}
|
||||
|
||||
void ncdc_mainwindow_switch_chat(ncdc_mainwindow_t n)
|
||||
{
|
||||
return_if_true(n == NULL,);
|
||||
n->focus = FOCUS_CHAT;
|
||||
ncdc_mainwindow_update_focus(n);
|
||||
}
|
||||
|
||||
void ncdc_mainwindow_rightview(ncdc_mainwindow_t n)
|
||||
{
|
||||
return_if_true(n == NULL,);
|
||||
|
@ -6,18 +6,29 @@ bool is_logged_in(void)
|
||||
return dc_session_has_token(current_session);
|
||||
}
|
||||
|
||||
wchar_t *util_readkey(int e, WINDOW *win)
|
||||
wchar_t *util_readkey(int e)
|
||||
{
|
||||
wint_t esc[7] = {0};
|
||||
int i = 0;
|
||||
int len = 0;
|
||||
|
||||
return_if_true(e != KEY_ESCAPE, NULL);
|
||||
|
||||
esc[0] = e;
|
||||
for (i = 1; i < 6; i++) {
|
||||
if (wget_wch(win, esc+i) == ERR) {
|
||||
return NULL;
|
||||
esc[1] = fgetwc(stdin);
|
||||
|
||||
switch (esc[1]) {
|
||||
/* here it depends on the next character we read
|
||||
*/
|
||||
case L'[': len = 3; break;
|
||||
/* O codes move the cursor, and have one additional bit set
|
||||
*/
|
||||
case L'O': len = 1; break;
|
||||
default: len = 5;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
esc[i+2] = fgetwc(stdin);
|
||||
}
|
||||
|
||||
return wcsdup((wchar_t const *)esc);
|
||||
|
Loading…
Reference in New Issue
Block a user