Skip to content

Commit

Permalink
mouse: only type clicked chars if Ctrl pressed
Browse files Browse the repository at this point in the history
People click with mouse occasionally, and typing gets them by
surprise. With Ctrl it can't be unintentional.
  • Loading branch information
stsp committed Jan 26, 2025
1 parent 474441b commit 0da5350
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ area outside of a cursor row, and another activates when you click
inside the cursor row.

Left button:
- types clicked char
- if Ctrl pressed: type clicked char; otherwise do nothing
- moves the cursor to the clicked location

Middle button:
Expand Down
9 changes: 2 additions & 7 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,22 +578,17 @@ static void advance_cmd_arg(void)
return;
}

static unsigned short keyb_shift_states;
static unsigned short keyb_get_rawcode(void)
{
unsigned short c = getch();

if (c == 0x00/* || c == 0xE0*/)
c = getch()<<8;

if (c == KEY_INSERT)
keyb_shift_states ^= KEYB_FLAG_INSERT;

return c;
}
static unsigned short keyb_get_shift_states(void)
unsigned short keyb_get_shift_states(void)
{
return keyb_shift_states;
return bioskey(2);
}

static void prompt_for_and_get_cmd(void)
Expand Down
11 changes: 11 additions & 0 deletions src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@
*/
#define GET_ENHANCED_KEYSTROKE 0x10
#define GET_EXTENDED_SHIFT_STATES 0x12

#define KEYB_FLAG_RSHIFT 0x0001
#define KEYB_FLAG_LSHIFT 0x0002
#define KEYB_FLAG_CTRL 0x0004
#define KEYB_FLAG_ALT 0x0008
#define KEYB_FLAG_SCROLLOCK 0x0010
#define KEYB_FLAG_NUMLOCK 0x0020
#define KEYB_FLAG_CAPSLOCK 0x0040
#define KEYB_FLAG_INSERT 0x0080

#define KEY_ASCII(k) (k & 0x00FF)
#define KEY_SCANCODE(k) (k >> 0x08 )
#define KEY_EXTM(k) (k & 0xFF1F)
Expand Down Expand Up @@ -467,4 +476,6 @@ struct built_in_cmd
extern struct built_in_cmd cmd_table[];
extern const int CMD_TABLE_COUNT;

unsigned short keyb_get_shift_states(void);

#endif
4 changes: 4 additions & 0 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sys/farptr.h>
#include <go32.h>
#include "asm.h"
#include "command.h"
#include "mouse.h"

#define CF 1
Expand Down Expand Up @@ -78,6 +79,7 @@ static void mlb(int alt_fn, int x, int y)
{
__dpmi_regs r = { };
short c;
int shift = keyb_get_shift_states();

if (alt_fn) {
int cx = wherex();
Expand All @@ -89,6 +91,8 @@ static void mlb(int alt_fn, int x, int y)
mvxr(x - cx);
return;
}
if (!(shift & KEYB_FLAG_CTRL))
return;

_conio_gettext(x, y, x, y, &c);

Expand Down

0 comments on commit 0da5350

Please sign in to comment.