From 6db41aa8e8b1038de949b948b8217720a847ce7d Mon Sep 17 00:00:00 2001 From: cy384 Date: Sun, 27 Dec 2020 20:44:37 -0500 Subject: [PATCH] add mouse mode preference --- ssheven-console.c | 15 +++++++++++---- ssheven.c | 29 ++++++++++++++++++++++++++--- ssheven.h | 2 ++ ssheven.r | 3 +++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/ssheven-console.c b/ssheven-console.c index 14c061a..47d777a 100644 --- a/ssheven-console.c +++ b/ssheven-console.c @@ -152,10 +152,17 @@ void draw_screen(Rect* r) // p is in window local coordinates void mouse_click(Point p, bool click) { - 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); + if (prefs.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) + { + // TODO: implement text selection + } } void draw_screen_color(Rect* r) diff --git a/ssheven.c b/ssheven.c index 5a203a9..f340b58 100644 --- a/ssheven.c +++ b/ssheven.c @@ -101,7 +101,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", (int)prefs.auth_type, (int)prefs.display_mode, (int)prefs.fg_color, (int)prefs.bg_color); + 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); 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"); @@ -163,6 +163,8 @@ void init_prefs(void) prefs.fg_color = blackColor; prefs.bg_color = whiteColor; + prefs.mouse_mode = CLICK_SEND; + prefs.loaded_from_file = 0; } @@ -211,7 +213,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%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); + 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); // add the size for the pascal strings prefs.hostname[0] = (unsigned char)strlen(prefs.hostname+1); @@ -482,12 +484,31 @@ 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); - } while(item != 1 && item != 9); + + // flip the mouse checkbox if clicked + if (item == 9) + { + SetControlValue(mouse_checkbox, !GetControlValue(mouse_checkbox)); + } + } while(item != 1 && item != 10); // save if OK'd if (item == 1) @@ -502,6 +523,8 @@ 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 73f6c2d..0984792 100644 --- a/ssheven.h +++ b/ssheven.h @@ -105,6 +105,8 @@ 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 0eb7826..f7b1527 100644 --- a/ssheven.r +++ b/ssheven.r @@ -541,6 +541,9 @@ 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" };