diff --git a/src/autocq.c b/src/autocq.c index 369b2871..8f86e55b 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -30,6 +30,8 @@ #include "clear_display.h" #include "cw_utils.h" #include "globalvars.h" +#include "keyer.h" +#include "keystroke_names.h" #include "printcall.h" #include "sendbuf.h" #include "stoptx.h" @@ -47,11 +49,42 @@ static int get_autocq_time() { if (trxmode != CWMODE) { return 0; // unknown } - const int cw_message_len = cw_message_length(message[11]); + const int cw_message_len = cw_message_length(message[AUTO_CQ_MSG]); return (int)(1200.0 / speed) * cw_message_len; } -#define NO_KEY -1 +#define NO_KEY (-1) + +// non-keypress events: +#define EVENT_CALLSIGN_GRAB (NO_KEY - 1) + +static int handle_immediate_key(int key) { + int cury, curx; + switch (key) { + // keyer speed change + case KEY_PPAGE: // + case KEY_NPAGE: // + + // auto CQ delay change + case TERM_KEY_CTRL_PGUP: + case TERM_KEY_ALT_PGUP: + case TERM_KEY_CTRL_PGDN: + case TERM_KEY_ALT_PGDN: + + getyx(stdscr, cury, curx); // save cursor + key = handle_common_key(key); + if (key == 0) { // key has been processed + move(cury, curx); // restore cursor + key = NO_KEY; // pretend there was no key press at all + } + + break; + + default: + // no action + } + return key; +} static int wait_50ms_for_key() { @@ -59,7 +92,7 @@ static int wait_50ms_for_key() { const int inchar = key_poll(); if (inchar > 0 && inchar != KEY_RESIZE) { - return inchar; + return handle_immediate_key(inchar); } return NO_KEY; @@ -105,6 +138,11 @@ static int wait_ms(int ms) { key = wait_50ms_for_key(); + // check if callsign grab happened + if (key == NO_KEY && current_qso.call[0] != 0) { + key = EVENT_CALLSIGN_GRAB; + } + wait_timer -= 50; update_timer -= 50; @@ -124,23 +162,19 @@ int auto_cq(void) { cqmode = AUTO_CQ; show_header_line(); - const long message_time = get_autocq_time(); - int key = NO_KEY; - // any key press terminates auto CQ loop + // any unhandled key press terminates auto CQ loop while (key == NO_KEY) { - send_standard_message(11); + send_standard_message(AUTO_CQ_MSG); move(12, 29); - attron(modify_attr(COLOR_PAIR(NORMCOLOR))); - // wait till message ends (calculated for CW, playtime for SSB) - // or any key press + // a key pressed or an event happened if (trxmode == CWMODE || trxmode == DIGIMODE) { - key = wait_ms(message_time); + key = wait_ms(get_autocq_time()); } else { key = vk_wait_finish(); } @@ -148,10 +182,15 @@ int auto_cq(void) { // wait between calls for (int delayval = cqdelay; delayval > 0 && key == NO_KEY; delayval--) { + attron(modify_attr(COLOR_PAIR(NORMCOLOR))); mvprintw(12, 29, "Auto CQ %-2d ", delayval); refreshp(); key = wait_ms(500); + + if (delayval > cqdelay) { // in case it was shortened while waiting + delayval = cqdelay; + } } mvaddstr(12, 29, spaces(13)); @@ -169,6 +208,10 @@ int auto_cq(void) { mvaddstr(12, 29, spaces(13)); printcall(); + if (key < NO_KEY) { // map events to NO_KEY + key = NO_KEY; + } + return toupper(key); } diff --git a/src/callinput.c b/src/callinput.c index a126bd02..a91354ec 100644 --- a/src/callinput.c +++ b/src/callinput.c @@ -794,40 +794,6 @@ int callinput(void) { } /* end switch */ - // Ctrl-, increase cqdelay by 1/2 second. - // Alt-, same for terminals that consume Ctrl-. - if ((key_kPRV3 && x == key_kPRV3) - || (key_kPRV5 && x == key_kPRV5)) { - - if (cqdelay <= 60) { - cqdelay++; - - attron(COLOR_PAIR(C_HEADER) | A_STANDOUT); - mvaddstr(0, 19, " "); - mvprintw(0, 19, "%i", cqdelay); - } - - break; - } - - - // Ctrl-, decrease cqdelay by 1/2 Second. - // Alt-, same for terminals that consume Ctrl-. - if ((key_kNXT3 && x == key_kNXT3) - || (key_kNXT5 && x == key_kNXT5)) { - - if (cqdelay >= 4) { - cqdelay--; - - attron(COLOR_PAIR(C_HEADER) | A_STANDOUT); - mvaddstr(0, 19, " "); - mvprintw(0, 19, "%i", cqdelay); - } - - break; - } - - /* Add character to call input field. */ if (valid_call_char(x)) { x = g_ascii_toupper(x); diff --git a/src/keyer.c b/src/keyer.c index 8e4777c7..8ae392f6 100644 --- a/src/keyer.c +++ b/src/keyer.c @@ -244,6 +244,34 @@ int handle_common_key(int key) { break; } + // Ctrl-, increase cqdelay by 1/2 second. + // Alt-, same for terminals that consume Ctrl-. + case TERM_KEY_CTRL_PGUP: + case TERM_KEY_ALT_PGUP: { + if (cqdelay <= 60) { + cqdelay++; + + attron(COLOR_PAIR(C_HEADER) | A_STANDOUT); + mvprintw(0, 19, "%-2i", cqdelay); + } + + break; + } + + // Ctrl-, decrease cqdelay by 1/2 cecond. + // Alt-, same for terminals that consume Ctrl-. + case TERM_KEY_CTRL_PGDN: + case TERM_KEY_ALT_PGDN: { + if (cqdelay >= 4) { + cqdelay--; + + attron(COLOR_PAIR(C_HEADER) | A_STANDOUT); + mvprintw(0, 19, "%-2i", cqdelay); + } + + break; + } + default: handled = false; } diff --git a/src/keystroke_names.h b/src/keystroke_names.h index 75721387..918822a0 100644 --- a/src/keystroke_names.h +++ b/src/keystroke_names.h @@ -78,3 +78,10 @@ #define RETURN CTRL_M #define SHIFT_F(n) (KEY_F(n) + 12) + +/* Terminal-specific keystrokes, see lookup_keys() */ +#define TERM_KEY_ALT_PGUP 10000 +#define TERM_KEY_ALT_PGDN 10001 +#define TERM_KEY_CTRL_PGUP 10002 +#define TERM_KEY_CTRL_PGDN 10003 + diff --git a/src/tlf.h b/src/tlf.h index 76a14bd3..72ac91f3 100644 --- a/src/tlf.h +++ b/src/tlf.h @@ -146,6 +146,7 @@ enum { /* special message numbers */ enum { + AUTO_CQ_MSG = 11, SP_TU_MSG = 12, CQ_TU_MSG = 13, SP_CALL_MSG = 24 diff --git a/src/ui_utils.c b/src/ui_utils.c index 3e8c096a..4a878f95 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -33,13 +33,12 @@ #include "showmsg.h" #include "splitscreen.h" - extern int ymax, xmax; -int key_kNXT3 = 0; -int key_kPRV3 = 0; -int key_kNXT5 = 0; -int key_kPRV5 = 0; +static int key_kNXT3 = 0; +static int key_kPRV3 = 0; +static int key_kNXT5 = 0; +static int key_kPRV5 = 0; static pthread_mutex_t panel_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -77,7 +76,7 @@ int modify_attr(int attr) { * \param capability - capability name * \return keycode or 0 if no associated key found */ -int lookup_key(char *capability) { +static int lookup_key(char *capability) { char *esc_sequence = NULL; int keycode = 0; @@ -169,6 +168,29 @@ static int getkey(bool wait) { return x; } +/* Map terminal-specific keys to our internal code + * as Ncurses does not provide predefined values for them + */ +static int map_terminal_key(int key) { + // Alt- + if (key_kNXT3 && key == key_kNXT3) { + return TERM_KEY_ALT_PGDN; + } + // Alt- + if (key_kPRV3 && key == key_kPRV3) { + return TERM_KEY_ALT_PGUP; + } + // Ctrl- + if (key_kNXT5 && key == key_kNXT5) { + return TERM_KEY_CTRL_PGDN; + } + // Ctrl- + if (key_kPRV5 && key == key_kPRV5) { + return TERM_KEY_CTRL_PGUP; + } + + return key; +} /* New onechar() that takes advantage of Ncurses keypad mode and processes * certain escaped keys and assigns them to Ncurses values known by @@ -194,7 +216,7 @@ static int onechar(void) { if (x == ERR) { stoptx(); - return x = ESCAPE; + return ESCAPE; } else if (x != 91) { @@ -339,6 +361,8 @@ static int onechar(void) { nodelay(stdscr, FALSE); } + x = map_terminal_key(x); + return x; } diff --git a/src/ui_utils.h b/src/ui_utils.h index 4b5e4151..52e70976 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -21,14 +21,8 @@ #ifndef UI_UTILS_H #define UI_UTILS_H -extern int key_kNXT3; -extern int key_kPRV3; -extern int key_kNXT5; -extern int key_kPRV5; - void refreshp(); int modify_attr(int attr); -int lookup_key(char *capability); void lookup_keys(); /** convenience macro to name alt-keys */