1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 06:38:37 -05:00

Change the term_mouse interface a little so that it gets passed

both the raw and the cooked mouse button, with the mapping being done in
advance by the front-end.  This is useful because it allows the front-end to
use information other than the raw button (e.g. the modifier state) to decide
which cooked button to generate.
.
Front ends other than the Mac one are untested, but they just call
translate_button() themselves and pass the result to term_mouse().

[originally from svn r2721]
This commit is contained in:
Ben Harris 2003-01-25 16:16:45 +00:00
parent 3f01fc87ec
commit af4be2e83e
5 changed files with 40 additions and 45 deletions

View File

@ -1,4 +1,4 @@
/* $Id: macterm.c,v 1.53 2003/01/25 15:15:40 ben Exp $ */ /* $Id: macterm.c,v 1.54 2003/01/25 16:16:44 ben Exp $ */
/* /*
* Copyright (c) 1999 Simon Tatham * Copyright (c) 1999 Simon Tatham
* Copyright (c) 1999, 2002 Ben Harris * Copyright (c) 1999, 2002 Ben Harris
@ -502,8 +502,8 @@ static void text_click(Session *s, EventRecord *event) {
lastact == MA_3CLK ? MA_CLICK : MA_NOTHING); lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
else else
lastact = MA_CLICK; lastact = MA_CLICK;
/* Fake right button with shift key */ term_mouse(s->term, MBT_LEFT,
term_mouse(s->term, event->modifiers & shiftKey ? MBT_RIGHT : MBT_LEFT, event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
lastact, col, row, event->modifiers & shiftKey, lastact, col, row, event->modifiers & shiftKey,
event->modifiers & controlKey, event->modifiers & optionKey); event->modifiers & controlKey, event->modifiers & optionKey);
lastsess = s; lastsess = s;
@ -513,8 +513,8 @@ static void text_click(Session *s, EventRecord *event) {
GetMouse(&localwhere); GetMouse(&localwhere);
col = PTOCC(localwhere.h); col = PTOCC(localwhere.h);
row = PTOCR(localwhere.v); row = PTOCR(localwhere.v);
term_mouse(s->term, term_mouse(s->term, MBT_LEFT,
event->modifiers & shiftKey ? MBT_RIGHT : MBT_LEFT, event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
MA_DRAG, col, row, event->modifiers & shiftKey, MA_DRAG, col, row, event->modifiers & shiftKey,
event->modifiers & controlKey, event->modifiers & controlKey,
event->modifiers & optionKey); event->modifiers & optionKey);
@ -523,25 +523,13 @@ static void text_click(Session *s, EventRecord *event) {
else if (row < 0) else if (row < 0)
term_scroll(s->term, 0, row); term_scroll(s->term, 0, row);
} }
term_mouse(s->term, event->modifiers & shiftKey ? MBT_RIGHT : MBT_LEFT, term_mouse(s->term, MBT_LEFT,
event->modifiers & shiftKey ? MBT_EXTEND : MBT_SELECT,
MA_RELEASE, col, row, event->modifiers & shiftKey, MA_RELEASE, col, row, event->modifiers & shiftKey,
event->modifiers & controlKey, event->modifiers & optionKey); event->modifiers & controlKey, event->modifiers & optionKey);
lastwhen = TickCount(); lastwhen = TickCount();
} }
Mouse_Button translate_button(void *frontend, Mouse_Button button)
{
switch (button) {
case MBT_LEFT:
return MBT_SELECT;
case MBT_RIGHT:
return MBT_EXTEND;
default:
return 0;
}
}
void write_clip(void *cookie, wchar_t *data, int len, int must_deselect) { void write_clip(void *cookie, wchar_t *data, int len, int must_deselect) {
/* /*

View File

@ -432,7 +432,6 @@ void write_clip(void *frontend, wchar_t *, int, int);
void get_clip(void *frontend, wchar_t **, int *); void get_clip(void *frontend, wchar_t **, int *);
void optimised_move(void *frontend, int, int, int); void optimised_move(void *frontend, int, int, int);
void set_raw_mouse_mode(void *frontend, int); void set_raw_mouse_mode(void *frontend, int);
Mouse_Button translate_button(void *frontend, Mouse_Button b);
void connection_fatal(void *frontend, char *, ...); void connection_fatal(void *frontend, char *, ...);
void fatalbox(char *, ...); void fatalbox(char *, ...);
void modalfatalbox(char *, ...); void modalfatalbox(char *, ...);
@ -505,7 +504,8 @@ void term_paint(Terminal *, Context, int, int, int, int, int);
void term_scroll(Terminal *, int, int); void term_scroll(Terminal *, int, int);
void term_pwron(Terminal *); void term_pwron(Terminal *);
void term_clrsb(Terminal *); void term_clrsb(Terminal *);
void term_mouse(Terminal *, Mouse_Button, Mouse_Action, int,int,int,int,int); void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
int,int,int,int,int);
void term_deselect(Terminal *); void term_deselect(Terminal *);
void term_update(Terminal *); void term_update(Terminal *);
void term_invalidate(Terminal *); void term_invalidate(Terminal *);

View File

@ -3802,8 +3802,8 @@ void term_do_paste(Terminal *term)
get_clip(term->frontend, NULL, NULL); get_clip(term->frontend, NULL, NULL);
} }
void term_mouse(Terminal *term, Mouse_Button b, Mouse_Action a, int x, int y, void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked,
int shift, int ctrl, int alt) Mouse_Action a, int x, int y, int shift, int ctrl, int alt)
{ {
pos selpoint; pos selpoint;
unsigned long *ldata; unsigned long *ldata;
@ -3844,7 +3844,7 @@ void term_mouse(Terminal *term, Mouse_Button b, Mouse_Action a, int x, int y,
if (term->ldisc) { if (term->ldisc) {
switch (b) { switch (braw) {
case MBT_LEFT: case MBT_LEFT:
encstate = 0x20; /* left button down */ encstate = 0x20; /* left button down */
break; break;
@ -3873,9 +3873,9 @@ void term_mouse(Terminal *term, Mouse_Button b, Mouse_Action a, int x, int y,
term->mouse_is_down = 0; term->mouse_is_down = 0;
break; break;
case MA_CLICK: case MA_CLICK:
if (term->mouse_is_down == b) if (term->mouse_is_down == braw)
return; return;
term->mouse_is_down = b; term->mouse_is_down = braw;
break; break;
default: break; /* placate gcc warning about enum use */ default: break; /* placate gcc warning about enum use */
} }
@ -3892,8 +3892,6 @@ void term_mouse(Terminal *term, Mouse_Button b, Mouse_Action a, int x, int y,
return; return;
} }
b = translate_button(term->frontend, b);
/* /*
* Set the selection type (rectangular or normal) at the start * Set the selection type (rectangular or normal) at the start
* of a selection attempt, from the state of Alt. * of a selection attempt, from the state of Alt.
@ -3907,13 +3905,13 @@ void term_mouse(Terminal *term, Mouse_Button b, Mouse_Action a, int x, int y,
term->seltype = default_seltype; term->seltype = default_seltype;
} }
if (b == MBT_SELECT && a == MA_CLICK) { if (bcooked == MBT_SELECT && a == MA_CLICK) {
deselect(term); deselect(term);
term->selstate = ABOUT_TO; term->selstate = ABOUT_TO;
term->seltype = default_seltype; term->seltype = default_seltype;
term->selanchor = selpoint; term->selanchor = selpoint;
term->selmode = SM_CHAR; term->selmode = SM_CHAR;
} else if (b == MBT_SELECT && (a == MA_2CLK || a == MA_3CLK)) { } else if (bcooked == MBT_SELECT && (a == MA_2CLK || a == MA_3CLK)) {
deselect(term); deselect(term);
term->selmode = (a == MA_2CLK ? SM_WORD : SM_LINE); term->selmode = (a == MA_2CLK ? SM_WORD : SM_LINE);
term->selstate = DRAGGING; term->selstate = DRAGGING;
@ -3921,11 +3919,12 @@ void term_mouse(Terminal *term, Mouse_Button b, Mouse_Action a, int x, int y,
term->selend = term->selstart; term->selend = term->selstart;
incpos(term->selend); incpos(term->selend);
sel_spread(term); sel_spread(term);
} else if ((b == MBT_SELECT && a == MA_DRAG) || } else if ((bcooked == MBT_SELECT && a == MA_DRAG) ||
(b == MBT_EXTEND && a != MA_RELEASE)) { (bcooked == MBT_EXTEND && a != MA_RELEASE)) {
if (term->selstate == ABOUT_TO && poseq(term->selanchor, selpoint)) if (term->selstate == ABOUT_TO && poseq(term->selanchor, selpoint))
return; return;
if (b == MBT_EXTEND && a != MA_DRAG && term->selstate == SELECTED) { if (bcooked == MBT_EXTEND && a != MA_DRAG &&
term->selstate == SELECTED) {
if (term->seltype == LEXICOGRAPHIC) { if (term->seltype == LEXICOGRAPHIC) {
/* /*
* For normal selection, we extend by moving * For normal selection, we extend by moving
@ -3986,7 +3985,8 @@ void term_mouse(Terminal *term, Mouse_Button b, Mouse_Action a, int x, int y,
term->selend.y = max(term->selanchor.y, selpoint.y); term->selend.y = max(term->selanchor.y, selpoint.y);
} }
sel_spread(term); sel_spread(term);
} else if ((b == MBT_SELECT || b == MBT_EXTEND) && a == MA_RELEASE) { } else if ((bcooked == MBT_SELECT || bcooked == MBT_EXTEND) &&
a == MA_RELEASE) {
if (term->selstate == DRAGGING) { if (term->selstate == DRAGGING) {
/* /*
* We've completed a selection. We now transfer the * We've completed a selection. We now transfer the
@ -3997,7 +3997,7 @@ void term_mouse(Terminal *term, Mouse_Button b, Mouse_Action a, int x, int y,
term->selstate = SELECTED; term->selstate = SELECTED;
} else } else
term->selstate = NO_SELECTION; term->selstate = NO_SELECTION;
} else if (b == MBT_PASTE } else if (bcooked == MBT_PASTE
&& (a == MA_CLICK && (a == MA_CLICK
#if MULTICLICK_ONLY_EVENT #if MULTICLICK_ONLY_EVENT
|| a == MA_2CLK || a == MA_3CLK || a == MA_2CLK || a == MA_3CLK

View File

@ -151,7 +151,7 @@ int font_dimension(void *frontend, int which)/* 0 for width, 1 for height */
* mouse or a means of faking it, and there is no need to switch * mouse or a means of faking it, and there is no need to switch
* buttons around at all. * buttons around at all.
*/ */
Mouse_Button translate_button(void *frontend, Mouse_Button button) static Mouse_Button translate_button(void *frontend, Mouse_Button button)
{ {
/* struct gui_data *inst = (struct gui_data *)frontend; */ /* struct gui_data *inst = (struct gui_data *)frontend; */
@ -937,7 +937,8 @@ gint button_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
x = (event->x - inst->cfg.window_border) / inst->font_width; x = (event->x - inst->cfg.window_border) / inst->font_width;
y = (event->y - inst->cfg.window_border) / inst->font_height; y = (event->y - inst->cfg.window_border) / inst->font_height;
term_mouse(inst->term, button, act, x, y, shift, ctrl, alt); term_mouse(inst->term, button, translate_button(button), act,
x, y, shift, ctrl, alt);
return TRUE; return TRUE;
} }
@ -964,7 +965,8 @@ gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
x = (event->x - inst->cfg.window_border) / inst->font_width; x = (event->x - inst->cfg.window_border) / inst->font_width;
y = (event->y - inst->cfg.window_border) / inst->font_height; y = (event->y - inst->cfg.window_border) / inst->font_height;
term_mouse(inst->term, button, MA_DRAG, x, y, shift, ctrl, alt); term_mouse(inst->term, button, translate_button(button), MA_DRAG,
x, y, shift, ctrl, alt);
return TRUE; return TRUE;
} }

View File

@ -78,6 +78,7 @@
#define WHEEL_DELTA 120 #define WHEEL_DELTA 120
#endif #endif
static Mouse_Button translate_button(void *frontend, Mouse_Button button);
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
unsigned char *output); unsigned char *output);
@ -1560,7 +1561,8 @@ static void click(Mouse_Button b, int x, int y, int shift, int ctrl, int alt)
if (send_raw_mouse && !(cfg.mouse_override && shift)) { if (send_raw_mouse && !(cfg.mouse_override && shift)) {
lastbtn = MBT_NOTHING; lastbtn = MBT_NOTHING;
term_mouse(term, b, MA_CLICK, x, y, shift, ctrl, alt); term_mouse(term, b, translate_button(b), MA_CLICK,
x, y, shift, ctrl, alt);
return; return;
} }
@ -1573,7 +1575,8 @@ static void click(Mouse_Button b, int x, int y, int shift, int ctrl, int alt)
lastact = MA_CLICK; lastact = MA_CLICK;
} }
if (lastact != MA_NOTHING) if (lastact != MA_NOTHING)
term_mouse(term, b, lastact, x, y, shift, ctrl, alt); term_mouse(term, b, translate_button(b), lastact,
x, y, shift, ctrl, alt);
lasttime = thistime; lasttime = thistime;
} }
@ -1581,7 +1584,7 @@ static void click(Mouse_Button b, int x, int y, int shift, int ctrl, int alt)
* Translate a raw mouse button designation (LEFT, MIDDLE, RIGHT) * Translate a raw mouse button designation (LEFT, MIDDLE, RIGHT)
* into a cooked one (SELECT, EXTEND, PASTE). * into a cooked one (SELECT, EXTEND, PASTE).
*/ */
Mouse_Button translate_button(void *frontend, Mouse_Button button) static Mouse_Button translate_button(void *frontend, Mouse_Button button)
{ {
if (button == MBT_LEFT) if (button == MBT_LEFT)
return MBT_SELECT; return MBT_SELECT;
@ -2052,7 +2055,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
is_alt_pressed()); is_alt_pressed());
SetCapture(hwnd); SetCapture(hwnd);
} else { } else {
term_mouse(term, button, MA_RELEASE, term_mouse(term, button, translate_button(button), MA_RELEASE,
TO_CHR_X(X_POS(lParam)), TO_CHR_X(X_POS(lParam)),
TO_CHR_Y(Y_POS(lParam)), wParam & MK_SHIFT, TO_CHR_Y(Y_POS(lParam)), wParam & MK_SHIFT,
wParam & MK_CONTROL, is_alt_pressed()); wParam & MK_CONTROL, is_alt_pressed());
@ -2077,7 +2080,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
b = MBT_MIDDLE; b = MBT_MIDDLE;
else else
b = MBT_RIGHT; b = MBT_RIGHT;
term_mouse(term, b, MA_DRAG, TO_CHR_X(X_POS(lParam)), term_mouse(term, b, translate_button(b), MA_DRAG,
TO_CHR_X(X_POS(lParam)),
TO_CHR_Y(Y_POS(lParam)), wParam & MK_SHIFT, TO_CHR_Y(Y_POS(lParam)), wParam & MK_SHIFT,
wParam & MK_CONTROL, is_alt_pressed()); wParam & MK_CONTROL, is_alt_pressed());
} }
@ -2612,12 +2616,13 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
if (send_raw_mouse && if (send_raw_mouse &&
!(cfg.mouse_override && shift_pressed)) { !(cfg.mouse_override && shift_pressed)) {
/* send a mouse-down followed by a mouse up */ /* send a mouse-down followed by a mouse up */
term_mouse(term, b, term_mouse(term, b, translate_button(b),
MA_CLICK, MA_CLICK,
TO_CHR_X(X_POS(lParam)), TO_CHR_X(X_POS(lParam)),
TO_CHR_Y(Y_POS(lParam)), shift_pressed, TO_CHR_Y(Y_POS(lParam)), shift_pressed,
control_pressed, is_alt_pressed()); control_pressed, is_alt_pressed());
term_mouse(term, b, MA_RELEASE, TO_CHR_X(X_POS(lParam)), term_mouse(term, b, translate_button(b),
MA_RELEASE, TO_CHR_X(X_POS(lParam)),
TO_CHR_Y(Y_POS(lParam)), shift_pressed, TO_CHR_Y(Y_POS(lParam)), shift_pressed,
control_pressed, is_alt_pressed()); control_pressed, is_alt_pressed());
} else { } else {