From 07b3e61517a71ef4af7827deebc93646a6f2ff3e Mon Sep 17 00:00:00 2001 From: zcsahok Date: Fri, 7 Nov 2025 21:28:06 +0000 Subject: [PATCH 1/8] stop auto CQ on callsign grab --- src/autocq.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/autocq.c b/src/autocq.c index 369b2871c..f21ceb8c9 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -51,7 +51,10 @@ static int get_autocq_time() { 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 wait_50ms_for_key() { @@ -105,6 +108,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; @@ -138,7 +146,7 @@ int auto_cq(void) { 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); } else { @@ -169,6 +177,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); } From f232471f67e8b0b707e55431fa736d17207f11ee Mon Sep 17 00:00:00 2001 From: zcsahok Date: Fri, 7 Nov 2025 22:03:24 +0000 Subject: [PATCH 2/8] handle some keys internally without stopping auto CQ --- src/autocq.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/autocq.c b/src/autocq.c index f21ceb8c9..b6bb0bd08 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -30,6 +30,7 @@ #include "clear_display.h" #include "cw_utils.h" #include "globalvars.h" +#include "keyer.h" #include "printcall.h" #include "sendbuf.h" #include "stoptx.h" @@ -56,13 +57,28 @@ static int get_autocq_time() { // non-keypress events: #define EVENT_CALLSIGN_GRAB (NO_KEY - 1) +static int handle_immediate_key(int key) { + switch (key) { + // keyer speed change + case KEY_PPAGE: // + case KEY_NPAGE: // + key = handle_common_key(key); + if (key == 0) { // key has been processed + key = NO_KEY; // so pretend there was no keypress at all + } + default: + // no action + } + return key; +} + static int wait_50ms_for_key() { usleep(50 * 1000); const int inchar = key_poll(); if (inchar > 0 && inchar != KEY_RESIZE) { - return inchar; + return handle_immediate_key(inchar); } return NO_KEY; @@ -136,7 +152,7 @@ int auto_cq(void) { 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); From 8137e3f5c899c0c86dbff1daeedbfce50634395e Mon Sep 17 00:00:00 2001 From: zcsahok Date: Sat, 8 Nov 2025 14:00:20 +0000 Subject: [PATCH 3/8] fix UI flicker --- src/autocq.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/autocq.c b/src/autocq.c index b6bb0bd08..eb09ab992 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -58,13 +58,16 @@ static int get_autocq_time() { #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: // + getyx(stdscr, cury, curx); // save cursor key = handle_common_key(key); - if (key == 0) { // key has been processed - key = NO_KEY; // so pretend there was no keypress at all + if (key == 0) { // key has been processed + move(cury, curx); // restore cursor + key = NO_KEY; // pretend there was no key press at all } default: // no action @@ -159,8 +162,6 @@ int auto_cq(void) { move(12, 29); - attron(modify_attr(COLOR_PAIR(NORMCOLOR))); - // wait till message ends (calculated for CW, playtime for SSB) // a key pressed or an event happened if (trxmode == CWMODE || trxmode == DIGIMODE) { @@ -172,6 +173,7 @@ 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(); From ab3b2518af0c1df1662c3e3f510a52786599b9f9 Mon Sep 17 00:00:00 2001 From: zcsahok Date: Sat, 8 Nov 2025 14:01:38 +0000 Subject: [PATCH 4/8] define AUTO_CQ_MSG --- src/autocq.c | 4 ++-- src/tlf.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/autocq.c b/src/autocq.c index eb09ab992..ea6a150f4 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -48,7 +48,7 @@ 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; } @@ -158,7 +158,7 @@ int auto_cq(void) { // 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); diff --git a/src/tlf.h b/src/tlf.h index 76a14bd34..72ac91f3f 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 From 448dcf0b4063a0e490f3f71406230a913ecbd1ad Mon Sep 17 00:00:00 2001 From: zcsahok Date: Sat, 8 Nov 2025 20:12:40 +0000 Subject: [PATCH 5/8] process Ctrl/Alt-PgUp/Dn keys in auto CQ these are special terminal-specific keys not known to curses, so had to map them to internal key values. moved Ctrl/Alt-PgUp/Dn handling to handle_common_key() --- src/autocq.c | 13 +++++++++++++ src/callinput.c | 34 ---------------------------------- src/keyer.c | 28 ++++++++++++++++++++++++++++ src/keystroke_names.h | 7 +++++++ src/ui_utils.c | 38 +++++++++++++++++++++++++++++++------- src/ui_utils.h | 6 ------ 6 files changed, 79 insertions(+), 47 deletions(-) diff --git a/src/autocq.c b/src/autocq.c index ea6a150f4..8f291c3bb 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -31,6 +31,7 @@ #include "cw_utils.h" #include "globalvars.h" #include "keyer.h" +#include "keystroke_names.h" #include "printcall.h" #include "sendbuf.h" #include "stoptx.h" @@ -63,12 +64,20 @@ static int handle_immediate_key(int 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 } + default: // no action } @@ -178,6 +187,10 @@ int auto_cq(void) { refreshp(); key = wait_ms(500); + + if (delayval > cqdelay) { // in case it was shortened while waiting + delayval = cqdelay; + } } mvaddstr(12, 29, spaces(13)); diff --git a/src/callinput.c b/src/callinput.c index a126bd028..a91354ec3 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 8e4777c7d..8ae392f65 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 757213875..918822a06 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/ui_utils.c b/src/ui_utils.c index 3e8c096a8..4a878f95b 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 4b5e4151c..52e709768 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 */ From 37c05d4da2160bffb445cf5d0aec9c0f4896d0c7 Mon Sep 17 00:00:00 2001 From: zcsahok Date: Sat, 8 Nov 2025 20:38:35 +0000 Subject: [PATCH 6/8] add missing break --- src/autocq.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/autocq.c b/src/autocq.c index 8f291c3bb..98df296cc 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -78,6 +78,8 @@ static int handle_immediate_key(int key) { key = NO_KEY; // pretend there was no key press at all } + break; + default: // no action } From f081990ac707a58a29390c9940744f01e8e26794 Mon Sep 17 00:00:00 2001 From: zcsahok Date: Sat, 8 Nov 2025 21:16:21 +0000 Subject: [PATCH 7/8] astyle --- src/autocq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/autocq.c b/src/autocq.c index 98df296cc..1329c1366 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -78,7 +78,7 @@ static int handle_immediate_key(int key) { key = NO_KEY; // pretend there was no key press at all } - break; + break; default: // no action From fa14a06e9efe4696ed44eb1e0ea8b889aa51efc5 Mon Sep 17 00:00:00 2001 From: zcsahok Date: Mon, 10 Nov 2025 20:51:13 +0000 Subject: [PATCH 8/8] move cq time calculation into the loop --- src/autocq.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/autocq.c b/src/autocq.c index 1329c1366..8f86e55be 100644 --- a/src/autocq.c +++ b/src/autocq.c @@ -162,8 +162,6 @@ int auto_cq(void) { cqmode = AUTO_CQ; show_header_line(); - const long message_time = get_autocq_time(); - int key = NO_KEY; // any unhandled key press terminates auto CQ loop @@ -176,7 +174,7 @@ int auto_cq(void) { // wait till message ends (calculated for CW, playtime for SSB) // 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(); }