From 7678ae0779a755277cf58aeec5104f0a58841693 Mon Sep 17 00:00:00 2001 From: cy384 Date: Mon, 11 Jan 2021 17:21:47 -0500 Subject: [PATCH] only send mouse clicks when the console wants them (version->0.8.5) --- ssheven-console.c | 9 +++++++-- ssheven-constants.r | 8 ++++---- ssheven.c | 31 ++++--------------------------- ssheven.h | 4 ++-- ssheven.r | 3 --- 5 files changed, 17 insertions(+), 38 deletions(-) diff --git a/ssheven-console.c b/ssheven-console.c index 37cd6c0..016d734 100644 --- a/ssheven-console.c +++ b/ssheven-console.c @@ -13,6 +13,8 @@ #include +#include + char key_to_vterm[256] = { VTERM_KEY_NONE }; void setup_key_translation(void) @@ -150,14 +152,14 @@ inline int idx2qd(VTermColor c) // p is in window local coordinates void mouse_click(Point p, bool click) { - if (prefs.mouse_mode == CLICK_SEND) + if (con.mouse_mode == CLICK_SEND) { int row = p.v / con.cell_height; int col = p.h / con.cell_width; vterm_mouse_move(con.vterm, row, col, VTERM_MOD_NONE); vterm_mouse_button(con.vterm, 1, click, VTERM_MOD_NONE); } - else if (prefs.mouse_mode == CLICK_SELECT) + else if (con.mouse_mode == CLICK_SELECT) { // TODO: implement text selection } @@ -545,6 +547,9 @@ int settermprop(VTermProp prop, VTermValue *val, void *user) case VTERM_PROP_REVERSE: //bool case VTERM_PROP_CURSORSHAPE: // number case VTERM_PROP_MOUSE: // number + // record whether or not the terminal wants mouse clicks + con.mouse_mode = (val->number | VTERM_MOUSE_WANT_CLICK) ? CLICK_SEND : CLICK_SELECT; + return 1; case VTERM_PROP_CURSORBLINK: // bool case VTERM_PROP_ALTSCREEN: // bool default: diff --git a/ssheven-constants.r b/ssheven-constants.r index a9609cb..82b77ff 100644 --- a/ssheven-constants.r +++ b/ssheven-constants.r @@ -4,11 +4,11 @@ #define __SSHEVEN_CONSTANTS_R__ /* so many versions */ -#define SSHEVEN_VERSION "0.8.4" -#define SSHEVEN_LONG_VERSION "0.8.4 prerelease, by cy384" -#define SSHEVEN_DESCRIPTION "ssheven 0.8.4 by cy384" +#define SSHEVEN_VERSION "0.8.5" +#define SSHEVEN_LONG_VERSION "0.8.5 prerelease, by cy384" +#define SSHEVEN_DESCRIPTION "ssheven 0.8.5 by cy384" #define SSHEVEN_VERSION_MAJOR 0x00 -#define SSHEVEN_VERSION_MINOR 0x84 +#define SSHEVEN_VERSION_MINOR 0x85 #define SSHEVEN_VERSION_PRERELEASE 0x01 /* options: development, alpha, beta, release */ diff --git a/ssheven.c b/ssheven.c index 4cc4aa2..565fc19 100644 --- a/ssheven.c +++ b/ssheven.c @@ -25,7 +25,7 @@ #include // sinful globals -struct ssheven_console con = { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 1, NULL, NULL }; +struct ssheven_console con = { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 1, CLICK_SELECT, NULL, NULL }; struct ssheven_ssh_connection ssh_con = { NULL, NULL, kOTInvalidEndpointRef, NULL, NULL }; struct preferences prefs; @@ -118,7 +118,7 @@ int save_prefs(void) memset(output_buffer, 0, write_length); long int i = snprintf(output_buffer, write_length, "%d\n%d\n", prefs.major_version, prefs.minor_version); - i += snprintf(output_buffer+i, write_length-i, "%d\n%d\n%d\n%d\n%d\n", (int)prefs.auth_type, (int)prefs.display_mode, (int)prefs.fg_color, (int)prefs.bg_color, (int)prefs.mouse_mode); + i += snprintf(output_buffer+i, write_length-i, "%d\n%d\n%d\n%d\n", (int)prefs.auth_type, (int)prefs.display_mode, (int)prefs.fg_color, (int)prefs.bg_color); snprintf(output_buffer+i, prefs.hostname[0]+1, "%s", prefs.hostname+1); i += prefs.hostname[0]; i += snprintf(output_buffer+i, write_length-i, "\n"); @@ -180,8 +180,6 @@ void init_prefs(void) prefs.fg_color = blackColor; prefs.bg_color = whiteColor; - prefs.mouse_mode = CLICK_SELECT; - prefs.loaded_from_file = 0; } @@ -230,7 +228,7 @@ void load_prefs(void) if ((prefs.major_version == SSHEVEN_VERSION_MAJOR) && (prefs.minor_version == SSHEVEN_VERSION_MINOR)) { prefs.loaded_from_file = 1; - items_got = sscanf(buffer, "%d\n%d\n%d\n%d\n%d\n%d\n%d\n%255[^\n]\n%255[^\n]\n%255[^\n]\n%[^\n]\n%[^\n]", &prefs.major_version, &prefs.minor_version, (int*)&prefs.auth_type, (int*)&prefs.display_mode, &prefs.fg_color, &prefs.bg_color, (int*)&prefs.mouse_mode, prefs.hostname+1, prefs.username+1, prefs.port+1, prefs.privkey_path, prefs.pubkey_path); + items_got = sscanf(buffer, "%d\n%d\n%d\n%d\n%d\n%d\n%255[^\n]\n%255[^\n]\n%255[^\n]\n%[^\n]\n%[^\n]", &prefs.major_version, &prefs.minor_version, (int*)&prefs.auth_type, (int*)&prefs.display_mode, &prefs.fg_color, &prefs.bg_color, prefs.hostname+1, prefs.username+1, prefs.port+1, prefs.privkey_path, prefs.pubkey_path); // add the size for the pascal strings prefs.hostname[0] = (unsigned char)strlen(prefs.hostname+1); @@ -357,31 +355,12 @@ void preferences_window(void) fg_color_menu = (ControlHandle)itemH; SetControlValue(fg_color_menu, qd_color_to_menu_item(prefs.fg_color)); - // get handle and set mouse mode checkbox - ControlHandle mouse_checkbox; - GetDialogItem(dlg, 9, &type, &itemH, &box); - mouse_checkbox = (ControlHandle)itemH; - if (prefs.mouse_mode == CLICK_SEND) - { - SetControlValue(mouse_checkbox, 1); - } - else - { - SetControlValue(mouse_checkbox, 0); - } - // let the modalmanager do everything // stop on ok or cancel short item; do { ModalDialog(NULL, &item); - - // flip the mouse checkbox if clicked - if (item == 9) - { - SetControlValue(mouse_checkbox, !GetControlValue(mouse_checkbox)); - } - } while(item != 1 && item != 10); + } while(item != 1 && item != 9); // save if OK'd if (item == 1) @@ -396,8 +375,6 @@ void preferences_window(void) prefs.bg_color = menu_item_to_qd_color(GetControlValue(bg_color_menu)); prefs.fg_color = menu_item_to_qd_color(GetControlValue(fg_color_menu)); - prefs.mouse_mode = GetControlValue(mouse_checkbox) ? CLICK_SEND : CLICK_SELECT; - save_prefs(); prefs.bg_color = save_bg; diff --git a/ssheven.h b/ssheven.h index ec01ec1..81c9ecf 100644 --- a/ssheven.h +++ b/ssheven.h @@ -37,6 +37,8 @@ struct ssheven_console long int last_cursor_blink; int cursor_visible; + enum { CLICK_SEND, CLICK_SELECT } mouse_mode; + VTerm* vterm; VTermScreen* vts; }; @@ -80,8 +82,6 @@ struct preferences enum { FASTEST, MONOCHROME, COLOR } display_mode; int fg_color; int bg_color; - - enum { CLICK_SEND, CLICK_SELECT } mouse_mode; }; extern struct preferences prefs; diff --git a/ssheven.r b/ssheven.r index f7b1527..0eb7826 100644 --- a/ssheven.r +++ b/ssheven.r @@ -541,9 +541,6 @@ resource 'DITL' (DITL_PREFERENCES) { { 70, 150, 89, 300 }, Control { enabled, CNTL_PREF_FG_COLOR }; - { 95, 150, 112, 290 }, - CheckBox { enabled, "Send mouse clicks" }; - { 115, 10, 135, 90 }, Button { enabled, "Cancel" };