[w3m-dev-en 00026] Re: FreeBSD sysmouse support

From: Christian Weisgerber (w3m-dev-en@mips.rhein-neckar.de)
Date: Sun Jan 23 2000 - 17:42:08 CST


I wrote:

> terms.c: mouse_end():
> - Doesn't do anything at all for sysmouse, because mouse handling is
> automatically reset by the console driver on program exit.

Here is an updated version of the patch to terms.c.
Now mouse_end() shuts down sysmouse operation. This is useful if
we actually suspend the mouse in msToggle(). I'm still unclear what
functionality should go into mouse_end() and which into mouse_inactive().

--- terms.c.orig Fri Jan 21 09:32:03 2000
+++ terms.c Mon Jan 24 00:28:00 2000
@@ -15,6 +15,16 @@
 #ifdef USE_GPM
 #include <gpm.h>
 #endif
+#ifdef USE_SYSMOUSE
+#include <machine/console.h>
+#ifndef FBIO_GETMODE /* FreeBSD 3.x */
+#define FBIO_GETMODE CONS_GET
+#define FBIO_MODEINFO CONS_MODEINFO
+#endif
+int (*sysm_handler)(int x, int y, int nbs, int obs);
+static int cwidth = 8, cheight = 16;
+static int xpos, ypos, buttons;
+#endif
 #ifdef MOUSE
 static int is_xterm = 0;
 #endif
@@ -1423,6 +1433,59 @@
 }
 #endif
 
+#ifdef USE_SYSMOUSE
+int
+sysm_getch()
+{
+ fd_set rfd;
+ int key;
+ int nbs, x, y;
+ static int obs = 0;
+
+ FD_ZERO(&rfd);
+ FD_SET(tty, &rfd);
+ while (select(tty+1, &rfd, NULL, NULL, NULL) <= 0) {
+ if (errno == EINTR) {
+ x = xpos / cwidth;
+ y = ypos / cheight;
+ nbs = buttons;
+ key = (*sysm_handler)(x, y, nbs, obs);
+ obs = nbs;
+ if (key != 0)
+ return key;
+ }
+ }
+ return getch();
+}
+
+int
+do_getch()
+{
+ if (is_xterm)
+ return getch();
+ else
+ return sysm_getch();
+}
+
+MySignalHandler
+sysmouse(SIGNAL_ARG)
+{
+ struct mouse_info mi;
+
+ mi.operation = MOUSE_GETINFO;
+ if (ioctl(tty, CONS_MOUSECTL, &mi) == -1)
+ return;
+ xpos = mi.u.data.x;
+ ypos = mi.u.data.y;
+ buttons = mi.u.data.buttons & 0x7;
+ /* for cosmetic bug in syscons.c on FreeBSD 3.[34] */
+ mi.operation = MOUSE_HIDE;
+ ioctl(tty, CONS_MOUSECTL, &mi);
+ mi.operation = MOUSE_SHOW;
+ ioctl(tty, CONS_MOUSECTL, &mi);
+}
+#endif
+
 void
 bell(void)
 {
@@ -1465,12 +1528,22 @@
 #ifdef USE_GPM
   Gpm_Connect conn;
   extern int gpm_process_mouse(Gpm_Event*,void*);
+#endif USE_GPM
+#ifdef USE_SYSMOUSE
+ mouse_info_t mi;
+ video_info_t vi;
+ extern int sysm_process_mouse();
+#endif
 
- if (mouseActive) return;
+#if defined(USE_GPM) || defined(USE_SYSMOUSE)
+ if (mouseActive)
+ return;
+#endif
   term = getenv("TERM");
   if (!strncmp(term,"kterm",5) || !strncmp(term,"xterm",5)) {
     is_xterm = 1;
   }
+#ifdef USE_GPM
   else {
     conn.eventMask = ~0;
     conn.defaultMask = GPM_MOVE|GPM_HARD;
@@ -1479,10 +1552,24 @@
     Gpm_Open(&conn,0); /* don't care even if it fails */
     gpm_handler = gpm_process_mouse;
   }
-#else
- term = getenv("TERM");
- if (!strncmp(term,"kterm",5) || !strncmp(term,"xterm",5)) {
- is_xterm = 1;
+#endif
+#ifdef USE_SYSMOUSE
+ else {
+ if (ioctl(tty, FBIO_GETMODE, &vi.vi_mode) != -1 &&
+ ioctl(tty, FBIO_MODEINFO, &vi) != -1) {
+ cwidth = vi.vi_cwidth;
+ cheight = vi.vi_cheight;
+ }
+ signal(SIGUSR2, SIG_IGN);
+ mi.operation = MOUSE_MODE;
+ mi.u.mode.mode = 0;
+ mi.u.mode.signal = SIGUSR2;
+ if (ioctl(tty, CONS_MOUSECTL, &mi) != -1) {
+ signal(SIGUSR2, sysmouse);
+ mi.operation = MOUSE_SHOW;
+ ioctl(tty, CONS_MOUSECTL, &mi);
+ sysm_handler = sysm_process_mouse;
+ }
   }
 #endif
   mouseActive = 1;
@@ -1497,6 +1584,15 @@
 #ifdef USE_GPM
   else
     Gpm_Close();
+#endif
+#ifdef USE_SYSMOUSE
+ else {
+ mouse_info_t mi;
+ mi.operation = MOUSE_MODE;
+ mi.u.mode.mode = 0;
+ mi.u.mode.signal = 0;
+ ioctl(tty, CONS_MOUSECTL, &mi);
+ }
 #endif
   mouseActive = 0;
 }

-- 
Christian "naddy" Weisgerber                  naddy@mips.rhein-neckar.de



This archive was generated by hypermail 2b29 : Wed Jul 19 2000 - 10:30:43 CDT