aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2001-12-12 17:04:20 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2001-12-12 17:04:20 +0000
commit776c1fa566c5fbf9ca7d64722bbce14664e78011 (patch)
tree7b9978b79d3c42b5a3a182d9d2d15569b03f98f8
parent[w3m-dev 02651] search keymap using hash (diff)
downloadw3m-776c1fa566c5fbf9ca7d64722bbce14664e78011.tar.gz
w3m-776c1fa566c5fbf9ca7d64722bbce14664e78011.zip
[w3m-dev 02541] mouse support on cygwin
From: Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
Diffstat (limited to '')
-rw-r--r--ChangeLog28
-rw-r--r--linein.c11
-rw-r--r--terms.c274
-rw-r--r--terms.h8
4 files changed, 220 insertions, 101 deletions
diff --git a/ChangeLog b/ChangeLog
index afd82c0..9605de8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2001-12-13 Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
+
+ * [w3m-dev 02541] mouse support on cygwin
+ * linein.c (_esc): ignore ESC M <ch> <ch> <ch> on cygwin
+ * terms.c (is_xterm): not static on cygwin
+ * terms.c (ConInV): INPUT_RECORD * -> char *
+ * terms.c (MouseConToXTerm): deleted
+ * terms.c (iMouseConXTerm): deleted
+ * terms.c (expand_win32_console_input_buffer): added
+ * terms.c (read_win32_console_input): use PeekConsoleInput
+ and ReadConsole
+ * terms.c (read_win32_console): use read_win32_console_input()
+ * terms.c (cmp_tv): added
+ * terms.c (subtract_tv): added
+ * terms.c (select_or_poll_win32_console): added
+ * terms.c (select_win32_console): added
+ * terms.c (xterm_mouse_term): deleted
+ * terms.c (mouse_term_info): added
+ * terms.c (set_tty): modified to use mouse_term_info
+ * terms.c (sleep_till_anykey): use select_win32_console on cygwin
+ * terms.c (mouse_init): check is_xterm flag
+ * terms.c (mouse_end): check is_xterm flag
+ * terms.h (is_xterm): if cygwin
+ * terms.h (NEED_XTERM_ON): added
+ * terms.h (NEED_XTERM_OFF): added
+
2001-12-11 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 02651] search keymap using hash
@@ -1199,4 +1225,4 @@
* release-0-2-1
* import w3m-0.2.1
-$Id: ChangeLog,v 1.124 2001/12/10 17:02:43 ukai Exp $
+$Id: ChangeLog,v 1.125 2001/12/12 17:04:20 ukai Exp $
diff --git a/linein.c b/linein.c
index 60fd81e..3b3fd31 100644
--- a/linein.c
+++ b/linein.c
@@ -1,4 +1,4 @@
-/* $Id: linein.c,v 1.16 2001/12/07 08:01:33 ukai Exp $ */
+/* $Id: linein.c,v 1.17 2001/12/12 17:04:21 ukai Exp $ */
#include "fm.h"
#include "local.h"
#include "myctype.h"
@@ -432,6 +432,15 @@ _esc(void)
case 'D':
_mvL();
break;
+#if defined(__CYGWIN__) && defined(USE_MOUSE)
+ case 'M':
+ if ((is_xterm & (NEED_XTERM_ON | NEED_XTERM_OFF)) == NEED_XTERM_ON) {
+ getch();
+ getch();
+ getch();
+ }
+ break;
+#endif
}
break;
case CTRL_I:
diff --git a/terms.c b/terms.c
index 7d195b2..58caef0 100644
--- a/terms.c
+++ b/terms.c
@@ -1,4 +1,4 @@
-/* $Id: terms.c,v 1.21 2001/12/09 13:59:04 ukai Exp $ */
+/* $Id: terms.c,v 1.22 2001/12/12 17:04:21 ukai Exp $ */
/*
* An original curses library for EUC-kanji by Akinori ITO, December 1989
* revised by Akinori ITO, January 1995
@@ -33,7 +33,11 @@ static int cwidth = 8, cheight = 16;
static int xpix, ypix, nbs, obs = 0;
#endif /* use_SYSMOUSE */
-static int is_xterm = 0;
+#ifndef __CYGWIN__
+static
+#endif
+int is_xterm = 0;
+
void mouse_init(), mouse_end();
int mouseActive = 0;
#endif /* USE_MOUSE */
@@ -58,11 +62,9 @@ extern int CodePage;
static HANDLE hConIn;
static int isWin95;
static int isWinConsole;
-static INPUT_RECORD *ConInV;
+static char *ConInV;
static int iConIn, nConIn, nConInMax;
#ifdef USE_MOUSE
-static char MouseConToXTerm[sizeof("\033[M !!") - sizeof("")];
-static int iMouseConToXTerm;
static MOUSE_EVENT_RECORD lastConMouse;
#endif
@@ -109,42 +111,73 @@ init_win32_console_handle(void)
}
}
+static void
+expand_win32_console_input_buffer(int n)
+{
+ if (nConIn + n >= nConInMax) {
+ char *oldv;
+
+ nConInMax = ((nConIn + n) / 2 + 1) * 3;
+ oldv = ConInV;
+ ConInV = GC_MALLOC_ATOMIC(nConInMax);
+ memcpy(ConInV, oldv, nConIn);
+ }
+}
+
static int
read_win32_console_input(void)
{
- INPUT_RECORD *p;
+ INPUT_RECORD rec;
DWORD nevents;
- if (nConIn >= nConInMax) {
- INPUT_RECORD *oldv;
+ if (PeekConsoleInput(hConIn, &rec, 1, &nevents) && nevents) {
+ switch (rec.EventType) {
+ case KEY_EVENT:
+ expand_win32_console_input_buffer(3);
- nConInMax = (nConInMax / 2 + 1) * 3;
- oldv = ConInV;
- ConInV = GC_MALLOC_ATOMIC(sizeof(ConInV[0]) * nConInMax);
- memcpy(ConInV, oldv, sizeof(ConInV[0]) * nConIn);
+ if (ReadConsole(hConIn, &ConInV[nConIn], 1, &nevents, NULL)) {
+ nConIn += nevents;
+ return nevents;
}
- p = &ConInV[nConIn];
-
- if (ReadConsoleInput(hConIn, p, 1, &nevents) && nevents) {
- switch (p->EventType) {
- case KEY_EVENT:
- if (p->Event.KeyEvent.bKeyDown
- || !p->Event.KeyEvent.uChar.AsciiChar)
break;
#ifdef USE_MOUSE
- event_found:
-#endif
- ++nConIn;
- return 1;
-#ifdef USE_MOUSE
case MOUSE_EVENT:
- if (mouseActive && p->Event.MouseEvent.dwButtonState & ~(~0 << 5))
- goto event_found;
+ if ((lastConMouse.dwButtonState ^ rec.Event.MouseEvent.dwButtonState) & ~(~0 << 5)) {
+ int down;
+ MOUSE_EVENT_RECORD *mer;
+ INPUT_RECORD dummy;
+
+ expand_win32_console_input_buffer(6);
+ mer = &rec.Event.MouseEvent;
+ ConInV[nConIn] = '\033';
+ ConInV[nConIn + 1] = '[';
+ ConInV[nConIn + 2] = 'M';
+
+ if (~(mer->dwButtonState) & lastConMouse.dwButtonState & ~(~0 << 5))
+ ConInV[nConIn + 3] = MOUSE_BTN_UP + ' ';
+ else if (!(down = mer->dwButtonState & ~lastConMouse.dwButtonState & ~(~0 << 5)))
+ break;
+ else
+ ConInV[nConIn + 3] = (down & (1 << 0) ? MOUSE_BTN1_DOWN :
+ down & (1 << 1) ? MOUSE_BTN3_DOWN :
+ down & (1 << 2) ? MOUSE_BTN2_DOWN :
+ down & (1 << 3) ? MOUSE_BTN4_DOWN_XTERM :
+ MOUSE_BTN5_DOWN_XTERM) + ' ';
+
+ ConInV[nConIn + 4] = mer->dwMousePosition.X + '!';
+ ConInV[nConIn + 5] = mer->dwMousePosition.Y + '!';
+ nConIn += 6;
+ lastConMouse = *mer;
+ ReadConsoleInput(hConIn, &rec, 1, &nevents);
+ return 6;
+ }
#endif
default:
break;
}
+
+ ReadConsoleInput(hConIn, &rec, 1, &nevents);
}
return 0;
}
@@ -152,76 +185,115 @@ read_win32_console_input(void)
int
read_win32_console(char *s, int n)
{
- int i;
KEY_EVENT_RECORD *ker;
-#ifdef USE_MOUSE
- int down, btn;
- MOUSE_EVENT_RECORD *mer;
-#endif
if (hConIn == INVALID_HANDLE_VALUE)
return read(tty, s, n);
- for (i = 0; i < n;)
-#ifdef USE_MOUSE
- if (iMouseConToXTerm) {
- s[i++] = MouseConToXTerm[iMouseConToXTerm++];
+ if (n > 0)
+ for (;;) {
+ if (iConIn < nConIn) {
+ if (n > nConIn - iConIn)
+ n = nConIn - iConIn;
+
+ memcpy(s, ConInV, n);
+
+ if ((iConIn += n) >= nConIn)
+ iConIn = nConIn = 0;
- if (iMouseConToXTerm >= sizeof(MouseConToXTerm))
- iMouseConToXTerm = 0;
- }
- else
-#endif
- if (iConIn < nConIn)
- switch (ConInV[iConIn].EventType) {
-#ifdef USE_MOUSE
- case MOUSE_EVENT:
- if (mouseActive) {
- mer = &ConInV[iConIn++].Event.MouseEvent;
- MouseConToXTerm[0] = '\033';
- MouseConToXTerm[1] = '[';
- MouseConToXTerm[2] = 'M';
- MouseConToXTerm[4] = mer->dwMousePosition.X + '!';
- MouseConToXTerm[5] = mer->dwMousePosition.Y + '!';
- if (~(mer->dwButtonState) & lastConMouse.dwButtonState)
- MouseConToXTerm[3] = MOUSE_BTN_UP + ' ';
- else if (!
- (down =
- mer->dwButtonState & ~lastConMouse.
- dwButtonState & ~(~0 << 5))) {
- lastConMouse = *mer;
break;
}
- else
- MouseConToXTerm[3] =
- (down & (1 << 0) ? MOUSE_BTN1_DOWN : down &
- (1 << 1) ? MOUSE_BTN3_DOWN : down & (1 << 2) ?
- MOUSE_BTN2_DOWN : down & (1 << 3) ?
- MOUSE_BTN4_DOWN_XTERM : MOUSE_BTN5_DOWN_XTERM) +
- ' ';
-
- s[i++] = MouseConToXTerm[iMouseConToXTerm++];
- lastConMouse = *mer;
+
+ iConIn = nConIn = 0;
+
+ while (!read_win32_console_input())
+ ;
}
- else
- ++iConIn;
- break;
-#endif
- default:
- s[i++] = ConInV[iConIn++].Event.KeyEvent.uChar.AsciiChar;
- break;
+
+ return n;
+}
+
+static int
+cmp_tv(const struct timeval *tv_a, const struct timeval *tv_b)
+{
+ return ((tv_a->tv_sec < tv_b->tv_sec) ? -1 :
+ (tv_a->tv_sec > tv_b->tv_sec) ? 1 :
+ (tv_a->tv_usec < tv_b->tv_usec) ? -1 :
+ (tv_a->tv_usec > tv_b->tv_usec) ? 1 :
+ 0);
+}
+
+static int
+subtract_tv(struct timeval *dst, const struct timeval *src)
+{
+ if ((dst->tv_usec -= src->tv_usec) < 0) {
+ --(dst->tv_sec);
+ dst->tv_usec += 1000000;
+ }
+
+ return ((dst->tv_sec -= src->tv_sec) < 0 ? -1 :
+ !dst->tv_sec ? (dst->tv_usec < 0 ? -1 : !dst->tv_usec ? 0 : 1) : 1);
+}
+
+int
+select_or_poll_win32_console(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tout)
+{
+ int m;
+ DWORD nevents;
+
+ if ((m = select(n, rfds, wfds, efds, tout)) < 0)
+ return m;
+
+ if (iConIn < nConIn) {
+ FD_SET(tty, rfds);
+ ++m;
}
else {
iConIn = nConIn = 0;
- if (!read_win32_console_input())
- break;
+ while (GetNumberOfConsoleInputEvents(hConIn, &nevents) && nevents)
+ read_win32_console_input();
+
+ if (nConIn) {
+ FD_SET(tty, rfds);
+ ++m;
+ }
}
- if (iConIn >= nConIn)
- iConIn = nConIn = 0;
+ return m;
+}
+
+int
+select_win32_console(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tout)
+{
+ static struct timeval polltv = {0, 1000000 / CLOCKS_PER_SEC};
+ int m;
+ struct timeval tv;
- return i;
+ if (hConIn == INVALID_HANDLE_VALUE || tty < 0 || tty >= n || !rfds || !FD_ISSET(tty, rfds))
+ return select(n, rfds, wfds, efds, tout);
+
+ FD_CLR(tty, rfds);
+
+ if (tout) {
+ while (cmp_tv(tout, &polltv) > 0) {
+ tv = polltv;
+
+ if ((m = select_or_poll_win32_console(n, rfds, wfds, efds, &tv)))
+ return m;
+
+ subtract_tv(tout, &polltv);
+ }
+
+ return select_or_poll_win32_console(n, rfds, wfds, efds, tout);
+ }
+ else
+ for (;;) {
+ tv = polltv;
+
+ if ((m = select_or_poll_win32_console(n, rfds, wfds, efds, &tv)))
+ return m;
+ }
}
#endif
@@ -394,9 +466,17 @@ writestr(char *s)
#define MOVE(line,column) writestr(tgoto(T_cm,column,line));
#ifdef USE_MOUSE
-static char *xterm_mouse_term[] = {
- "xterm", "kterm", "rxvt", "cygwin",
- NULL
+static struct mouse_term_info {
+ char *term;
+ int flag;
+} xterm_mouse_term[] = {
+ {"xterm", NEED_XTERM_ON|NEED_XTERM_OFF},
+ {"kterm", NEED_XTERM_ON|NEED_XTERM_OFF},
+ {"rxvt", NEED_XTERM_ON|NEED_XTERM_OFF},
+#ifdef __CYGWIN__
+ {"cygwin", NEED_XTERM_ON},
+#endif
+ {NULL, 0}
};
#endif
@@ -422,10 +502,10 @@ set_tty(void)
#ifdef USE_MOUSE
{
char *term = getenv("TERM");
- char **p;
- for (p = xterm_mouse_term; *p != NULL; p++) {
- if (!strncmp(term, *p, strlen(*p))) {
- is_xterm = 1;
+ struct mouse_term_info *p;
+ for (p = xterm_mouse_term; p->term != NULL; p++) {
+ if (!strncmp(term, p->term, strlen(p->term))) {
+ is_xterm = p->flag;
break;
}
}
@@ -1883,7 +1963,13 @@ sleep_till_anykey(int sec, int purge)
FD_ZERO(&rfd);
FD_SET(tty, &rfd);
- if (select(tty + 1, &rfd, 0, 0, &tim) > 0 && purge) {
+ if (
+#ifdef __CYGWIN__
+ select_win32_console(tty + 1, &rfd, 0, 0, &tim)
+#else
+ select(tty + 1, &rfd, 0, 0, &tim)
+#endif
+ > 0 && purge) {
c = getch();
if (c == ESC_CODE)
skip_escseq();
@@ -2017,11 +2103,7 @@ mouse_init()
{
if (mouseActive)
return;
- if (is_xterm
-#ifdef __CYGWIN__
- && hConIn == INVALID_HANDLE_VALUE
-#endif
- ) {
+ if (is_xterm & NEED_XTERM_ON) {
XTERM_ON;
}
mouseActive = 1;
@@ -2032,11 +2114,7 @@ mouse_end()
{
if (mouseActive == 0)
return;
- if (is_xterm
-#ifdef __CYGWIN__
- && hConIn == INVALID_HANDLE_VALUE
-#endif
- ) {
+ if (is_xterm & NEED_XTERM_OFF) {
XTERM_OFF;
}
mouseActive = 0;
diff --git a/terms.h b/terms.h
index 19204b6..ca7bce7 100644
--- a/terms.h
+++ b/terms.h
@@ -1,4 +1,4 @@
-/* $Id: terms.h,v 1.4 2001/11/22 15:02:17 ukai Exp $ */
+/* $Id: terms.h,v 1.5 2001/12/12 17:04:21 ukai Exp $ */
#ifndef TERMS_H
#define TERMS_H
@@ -38,6 +38,12 @@ extern int LINES, COLS;
#define MOUSE_BTN_UP 3
#define MOUSE_BTN_RESET -1
#define MOUSE_SCROLL_LINE 5
+
+#ifdef __CYGWIN__
+extern int is_xterm;
+#endif
+#define NEED_XTERM_ON (1)
+#define NEED_XTERM_OFF (1<<1)
#endif
#endif /* not TERMS_H */