Adds mouse handling in FreeBSD console, should also work in DragonFly
(modify configure script first).
I am looking for feedback adding wsmouse support in vim (for NetBSD
and OpenBSD console).
Limitations and possible improvements:
Keyboard modifiers are not detected by sysmouse itself so I am
interested in possibility adding them is some other way.
Unresolved bugs:
Mouse handling in Command line mode is incorrect, it behaves
differently from xterm and GUI.
Does same behaviour/bug occur with vim (+mouse_gpm) in linux console
with gpm enabled?
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
diff -Nur vim71orig/runtime/doc/eval.txt vim71/runtime/doc/eval.txt
--- vim71orig/runtime/doc/eval.txt 2007-05-12 12:18:46.000000000 +0200
+++ vim71/runtime/doc/eval.txt 2008-04-07 13:29:07.000000000 +0200
@@ -5277,6 +5277,7 @@
mouseshape Compiled with support for 'mouseshape'.
mouse_dec Compiled with support for Dec terminal mouse.
mouse_gpm Compiled with support for gpm (Linux console mouse)
+mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
mouse_netterm Compiled with support for netterm mouse.
mouse_pterm Compiled with support for qnx pterm mouse.
mouse_xterm Compiled with support for xterm mouse.
diff -Nur vim71orig/runtime/doc/options.txt vim71/runtime/doc/options.txt
--- vim71orig/runtime/doc/options.txt 2007-05-12 12:18:47.000000000 +0200
+++ vim71/runtime/doc/options.txt 2008-04-07 13:29:07.000000000 +0200
@@ -4612,8 +4612,9 @@
global
{not in Vi}
Enable the use of the mouse. Only works for certain terminals
- (xterm, MS-DOS, Win32 |win32-mouse|, QNX pterm, and Linux console
- with gpm). For using the mouse in the GUI, see |gui-mouse|.
+ (xterm, MS-DOS, Win32 |win32-mouse|, QNX pterm, FreeBSD console with
+ sysmouse and Linux console with gpm). For using the mouse in
+ the GUI, see |gui-mouse|.
The mouse can be enabled for different modes:
n Normal mode
v Visual mode
diff -Nur vim71orig/runtime/doc/tags vim71/runtime/doc/tags
--- vim71orig/runtime/doc/tags 2007-05-12 14:09:10.000000000 +0200
+++ vim71/runtime/doc/tags 2008-04-07 13:29:07.000000000 +0200
@@ -1138,6 +1138,7 @@
+mouse_gpm various.txt /*+mouse_gpm*
+mouse_netterm various.txt /*+mouse_netterm*
+mouse_pterm various.txt /*+mouse_pterm*
++mouse_sysmouse various.txt /*+mouse_sysmouse*
+mouse_xterm various.txt /*+mouse_xterm*
+mouseshape various.txt /*+mouseshape*
+multi_byte various.txt /*+multi_byte*
@@ -7251,6 +7252,7 @@
syntax.txt syntax.txt /*syntax.txt*
syntax_cmd syntax.txt /*syntax_cmd*
sys-file-list help.txt /*sys-file-list*
+sysmouse term.txt /*sysmouse*
system() eval.txt /*system()*
system-vimrc starting.txt /*system-vimrc*
s~ change.txt /*s~*
diff -Nur vim71orig/runtime/doc/term.txt vim71/runtime/doc/term.txt
--- vim71orig/runtime/doc/term.txt 2007-05-12 12:18:47.000000000 +0200
+++ vim71/runtime/doc/term.txt 2008-04-07 13:29:07.000000000 +0200
@@ -583,8 +583,9 @@
:set mouse=a
Otherwise Vim won't recognize the mouse in all modes (See 'mouse').
-Currently the mouse is supported for Unix in an xterm window, in a Linux
-console (with GPM |gpm-mouse|), for MS-DOS and in a Windows console.
+Currently the mouse is supported for Unix in an xterm window, in a FreeBSD
+console (with |sysmouse|), in a Linux console (with GPM |gpm-mouse|), for
+MS-DOS and in a Windows console.
Mouse clicks can be used to position the cursor, select an area and paste.
These characters in the 'mouse' option tell in which situations the mouse will
@@ -789,6 +790,11 @@
This is like using CTRL-O in Insert mode. Select mode is used when the
'selectmode' option contains "mouse".
+ *sysmouse*
+The sysmouse is only supported when the |+mouse_sysmouse| feature was enabled
+at compile time. The sysmouse driver (in FreeBSD console) does not support
+keyboard modifiers.
+
*drag-status-line*
When working with several windows, the size of the windows can be changed by
dragging the status line with the mouse. Point the mouse at a status line,
diff -Nur vim71orig/runtime/doc/todo.txt vim71/runtime/doc/todo.txt
--- vim71orig/runtime/doc/todo.txt 2007-05-12 12:18:47.000000000 +0200
+++ vim71/runtime/doc/todo.txt 2008-04-07 13:29:07.000000000 +0200
@@ -3520,7 +3520,6 @@
8 Add 'mouse' flag, which sets a behavior like Visual mode, but automatic
yanking at the button-up event. Or like Select mode, but typing gets you
out of Select mode, instead of replacing the text. (Bhaskar)
-7 Checkout sysmouse() for FreeBSD console mouse support.
- Implement mouse support for the Amiga console.
- Using right mouse button to extend a blockwise selection should attach to
the nearest corner of the rectangle (four possible corners).
diff -Nur vim71orig/runtime/doc/various.txt vim71/runtime/doc/various.txt
--- vim71orig/runtime/doc/various.txt 2007-05-12 12:18:48.000000000 +0200
+++ vim71/runtime/doc/various.txt 2008-04-07 13:29:07.000000000 +0200
@@ -343,6 +343,7 @@
N *+mouse_gpm* Unix only: Linux console mouse handling |gpm-mouse|
B *+mouse_netterm* Unix only: netterm mouse handling |netterm-mouse|
N *+mouse_pterm* QNX only: pterm mouse handling |qnx-terminal|
+N *+mouse_sysmouse* Unix only: *BSD console mouse handling |sysmouse|
N *+mouse_xterm* Unix only: xterm mouse handling |xterm-mouse|
B *+multi_byte* Korean and other languages |multibyte|
*+multi_byte_ime* Win32 input method for multibyte chars |multibyte-ime|
diff -Nur vim71orig/src/Makefile vim71/src/Makefile
--- vim71orig/src/Makefile 2007-05-12 13:57:13.000000000 +0200
+++ vim71/src/Makefile 2008-04-07 13:29:07.000000000 +0200
@@ -49,6 +49,8 @@
# though your system supports it.
# - Uncomment the line with --disable-gpm to disable gpm support
# even though you have gpm libraries and includes
+# - Uncomment the line with --disable-sysmouse to disable moused support
+# for vim in console even though you have /dev/sysmouse
# - Uncomment one of the lines with CFLAGS and/or CC if you have
# something very special or want to tune the optimizer.
# - Search for the name of your system to see if it needs anything
@@ -450,6 +452,11 @@
# though you have gpm libraries and includes
#CONF_OPT_GPM = --disable-gpm
+# sysmouse - For mouse support on FreeBSD console via moused
+# Uncomment this when you do not want do include sysmouse support, even
+# though you have /dev/sysmouse
+#CONF_OPT_SYSMOUSE = --disable-sysmouse
+
# FEATURES - For creating Vim with more or less features
# Uncomment one of these lines when you want to include few to many features.
# The default is "normal".
@@ -1558,10 +1565,11 @@
$(CONF_OPT_DARWIN) $(CONF_OPT_PERL) $(CONF_OPT_PYTHON) \
$(CONF_OPT_TCL) $(CONF_OPT_RUBY) $(CONF_OPT_NLS) \
$(CONF_OPT_CSCOPE) $(CONF_OPT_MULTIBYTE) $(CONF_OPT_INPUT) \
- $(CONF_OPT_OUTPUT) $(CONF_OPT_GPM) $(CONF_OPT_WORKSHOP) \
- $(CONF_OPT_SNIFF) $(CONF_OPT_FEAT) $(CONF_TERM_LIB) \
- $(CONF_OPT_COMPBY) $(CONF_OPT_ACL) $(CONF_OPT_NETBEANS) \
- $(CONF_ARGS) $(CONF_OPT_MZSCHEME) $(CONF_OPT_PLTHOME)
+ $(CONF_OPT_OUTPUT) $(CONF_OPT_GPM) $(CONF_OPT_SYSMOUSE) \
+ $(CONF_OPT_WORKSHOP) $(CONF_OPT_SNIFF) $(CONF_OPT_FEAT) \
+ $(CONF_TERM_LIB) $(CONF_OPT_COMPBY) $(CONF_OPT_ACL) \
+ $(CONF_OPT_NETBEANS) $(CONF_ARGS) $(CONF_OPT_MZSCHEME) \
+ $(CONF_OPT_PLTHOME)
# Use "make reconfig" to rerun configure without cached values.
# When config.h changes, most things will be recompiled automatically.
diff -Nur vim71orig/src/auto/configure vim71/src/auto/configure
--- vim71orig/src/auto/configure 2007-05-12 13:49:09.000000000 +0200
+++ vim71/src/auto/configure 2008-04-07 13:29:07.000000000 +0200
@@ -871,6 +871,7 @@
--disable-gtktest Do not try to compile and run a test GTK program
--disable-acl Don't check for ACL support.
--disable-gpm Don't use gpm (Linux mouse daemon).
+ --disable-sysmouse Don't use sysmouse (FreeBSD console mouse).
--disable-nls Don't support NLS (gettext()).
Optional Packages:
@@ -13528,6 +13529,42 @@
echo "${ECHO_T}yes" >&6
fi
+echo "$as_me:$LINENO: checking --disable-sysmouse argument" >&5
+echo $ECHO_N "checking --disable-sysmouse argument... $ECHO_C" >&6
+# Check if --enable-sysmouse or --disable-sysmouse was given.
+if test "${enable_sysmouse+set}" = set; then
+ enableval="$enable_sysmouse"
+
+else
+ enable_sysmouse="yes"
+fi;
+
+if test "$enable_sysmouse" = "yes"; then
+ echo "$as_me:$LINENO: result: no" >&5
+ echo "${ECHO_T}no" >&6
+ echo "$as_me:$LINENO: checking for sysmouse" >&5
+ echo $ECHO_N "checking for sysmouse... $ECHO_C" >&6
+if test "${vi_cv_have_sysmouse+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test "`(uname) 2>/dev/null`" = FreeBSD; then
+ vi_cv_have_sysmouse=yes
+ else
+ echo $ECHO_N "result: no" >&5
+ echo "${ECHO_T}no" >&6
+ vi_cv_have_sysmouse=no
+ fi
+fi
+ if test $vi_cv_have_sysmouse = yes; then
+ echo "$as_me:$LINENO: result: yes" >&5
+ echo "${ECHO_T}yes" >&6
+ cat >>confdefs.h <<\_ACEOF
+#define HAVE_SYSMOUSE 1
+_ACEOF
+
+ fi
+fi
+
echo "$as_me:$LINENO: checking for rename" >&5
echo $ECHO_N "checking for rename... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
diff -Nur vim71orig/src/config.h.in vim71/src/config.h.in
--- vim71orig/src/config.h.in 2007-04-26 16:40:34.000000000 +0200
+++ vim71/src/config.h.in 2008-04-07 13:29:07.000000000 +0200
@@ -307,6 +307,9 @@
/* Define if you want to add support of GPM (Linux console mouse daemon) */
#undef HAVE_GPM
+/* Define if you want to add support of SYSMOUSE (FreeBSD mouse driver) */
+#undef HAVE_SYSMOUSE
+
/* Define if you want to include the Cscope interface. */
#undef FEAT_CSCOPE
diff -Nur vim71orig/src/configure.in vim71/src/configure.in
--- vim71orig/src/configure.in 2007-05-12 11:19:27.000000000 +0200
+++ vim71/src/configure.in 2008-04-07 13:29:07.000000000 +0200
@@ -2565,6 +2565,30 @@
AC_MSG_RESULT(yes)
fi
+AC_MSG_CHECKING(--disable-sysmouse argument)
+AC_ARG_ENABLE(sysmouse,
+ [ --disable-sysmouse Don't use moused (FreeBSD mouse daemon).], ,
+ [enable_sysmouse="yes"])
+
+if test "$enable_sysmouse" = "yes"; then
+ AC_MSG_RESULT(no)
+ dnl Checking if sysmouse support can be compiled
+ AC_CACHE_CHECK([for sysmouse], vi_cv_have_sysmouse,
+ AC_TRY_LINK(
+ [#include <sys/consio.h>
+ #include <sys/fbio.h>],
+ dnl Configure defines HAVE_SYSMOUSE, if it is defined feature.h
+ dnl defines FEAT_SYSMOUSE if mouse support is included
+ [vi_cv_have_sysmouse=yes],
+ [vi_cv_have_sysmouse=no])
+ )
+ if test $vi_cv_have_sysmouse = yes; then
+ AC_DEFINE(HAVE_SYSMOUSE)
+ fi
+else
+ AC_MSG_RESULT(yes)
+fi
+
dnl rename needs to be checked separately to work on Nextstep with cc
AC_MSG_CHECKING(for rename)
AC_TRY_LINK([#include <stdio.h>], [rename("this", "that")],
diff -Nur vim71orig/src/eval.c vim71/src/eval.c
--- vim71orig/src/eval.c 2007-05-07 21:47:32.000000000 +0200
+++ vim71/src/eval.c 2008-04-07 13:29:07.000000000 +0200
@@ -10855,6 +10855,9 @@
# ifdef FEAT_MOUSE_GPM
"mouse_gpm",
# endif
+# ifdef FEAT_SYSMOUSE
+ "mouse_sysmouse",
+# endif
# ifdef FEAT_MOUSE_JSB
"mouse_jsbterm",
# endif
diff -Nur vim71orig/src/feature.h vim71/src/feature.h
--- vim71orig/src/feature.h 2007-05-07 21:33:19.000000000 +0200
+++ vim71/src/feature.h 2008-04-07 13:38:13.000000000 +0200
@@ -1010,6 +1010,8 @@
* +mouse_gpm Unix only: Include code for Linux console mouse
* handling.
* +mouse_pterm PTerm mouse support for QNX
+ * +mouse_sysmouse Unix only: Include code for FreeBSD console mouse
+ * handling.
* +mouse Any mouse support (any of the above enabled).
*/
/* OS/2 and Amiga console have no mouse support */
@@ -1034,10 +1036,16 @@
#if defined(FEAT_NORMAL) && defined(HAVE_GPM)
# define FEAT_MOUSE_GPM
#endif
+
+#if defined(FEAT_NORMAL) && defined(HAVE_SYSMOUSE)
+# define FEAT_SYSMOUSE
+#endif
+
/* Define FEAT_MOUSE when any of the above is defined or FEAT_GUI. */
#if !defined(FEAT_MOUSE_TTY) && (defined(FEAT_MOUSE_XTERM) \
|| defined(FEAT_MOUSE_NET) || defined(FEAT_MOUSE_DEC) \
|| defined(DOS_MOUSE) || defined(FEAT_MOUSE_GPM) \
+ || defined(FEAT_SYSMOUSE) \
|| defined(FEAT_MOUSE_JSB) || defined(FEAT_MOUSE_PTERM))
# define FEAT_MOUSE_TTY /* include non-GUI mouse support */
#endif
diff -Nur vim71orig/src/os_unix.c vim71/src/os_unix.c
--- vim71orig/src/os_unix.c 2007-05-09 21:41:58.000000000 +0200
+++ vim71/src/os_unix.c 2008-04-08 01:49:54.000000000 +0200
@@ -87,6 +87,20 @@
static int mch_gpm_process __ARGS((void));
#endif
+#ifdef FEAT_SYSMOUSE
+# include <osreldate.h>
+# if (__FreeBSD_version >= 400017)
+# include <sys/consio.h>
+# include <sys/fbio.h>
+# else
+# include <machine/console.h>
+# endif
+
+static int sysmouse_open __ARGS((void));
+static void sysmouse_close __ARGS((void));
+static void mch_sysmouse __ARGS((int sig));
+#endif
+
/*
* end of autoconf section. To be extended...
*/
@@ -3155,6 +3169,22 @@
}
# endif
+# ifdef FEAT_SYSMOUSE
+ else
+ {
+ if (on)
+ {
+ if (sysmouse_open())
+ ison = TRUE;
+ }
+ else
+ {
+ sysmouse_close();
+ ison = FALSE;
+ }
+ }
+# endif
+
# ifdef FEAT_MOUSE_JSB
else
{
@@ -3233,7 +3263,7 @@
del_mouse_termcode(KS_MOUSE);
# endif
-# ifdef FEAT_MOUSE_GPM
+# if defined (FEAT_MOUSE_GPM) || defined (FEAT_SYSMOUSE)
if (!use_xterm_mouse()
# ifdef FEAT_GUI
&& !gui.in_use
@@ -5682,7 +5712,6 @@
/*
* Closes connection to gpm
- * returns non-zero if connection succesfully closed
*/
static void
gpm_close()
@@ -5777,6 +5806,107 @@
}
#endif /* FEAT_MOUSE_GPM */
+#ifdef FEAT_SYSMOUSE
+/*
+ * Initialize connection with sysmouse.
+ * Let virtual console inform us with SIGUSR2 for pending sysmouse
+ * output, any sysmouse output than will be processed via mch_sysmouse.
+ */
+ static int
+sysmouse_open()
+{
+ struct mouse_info sysmouse_info;
+
+ sysmouse_info.operation = MOUSE_MODE;
+ sysmouse_info.u.mode.mode = 0;
+ sysmouse_info.u.mode.signal = SIGUSR2;
+ if (ioctl(1, CONS_MOUSECTL, &sysmouse_info) != -1)
+ {
+ signal(SIGUSR2, mch_sysmouse);
+ sysmouse_info.operation = MOUSE_SHOW;
+ ioctl(1, CONS_MOUSECTL, &sysmouse_info);
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Stop processing SIGUSR2 signals, and also make sure that
+ * virtual console do not send us any sysmouse related signal.
+ */
+ static void
+sysmouse_close()
+{
+ struct mouse_info sysmouse_info;
+
+ signal(SIGUSR2, SIG_IGN);
+ sysmouse_info.operation = MOUSE_MODE;
+ sysmouse_info.u.mode.mode = 0;
+ sysmouse_info.u.mode.signal = 0;
+ ioctl(1, CONS_MOUSECTL, &sysmouse_info);
+}
+
+/*
+ * Gets info from sysmouse and adds special keys to input buf.
+ */
+ static void
+mch_sysmouse(int sig)
+{
+ struct mouse_info sysmouse_info;
+ struct video_info video;
+ char_u string[6];
+ int row, col;
+ int buttons;
+ static int oldbuttons;
+
+#ifdef FEAT_GUI
+ /* Don't put events in the input queue now. */
+ if (hold_gui_events)
+ return;
+#endif
+
+ sysmouse_info.operation = MOUSE_GETINFO;
+ if (ioctl(1, FBIO_GETMODE, &video.vi_mode) != -1 &&
+ ioctl(1, FBIO_MODEINFO, &video) != -1 &&
+ ioctl(1, CONS_MOUSECTL, &sysmouse_info) != -1)
+ {
+ row = sysmouse_info.u.data.y / video.vi_cheight;
+ col = sysmouse_info.u.data.x / video.vi_cwidth;
+ buttons = sysmouse_info.u.data.buttons;
+ string[0] = ESC; /* Our termcode */
+ string[1] = 'M';
+ string[2] = 'G';
+ if ((buttons != 0) && (oldbuttons == buttons))
+ string[3] = (char_u)(MOUSE_DRAG);
+ else
+ {
+ switch (buttons)
+ {
+ case 0:
+ string[3] = (char_u)(MOUSE_RELEASE);
+ break;
+ case 1:
+ string[3] = (char_u)(MOUSE_LEFT);
+ break;
+ case 2:
+ string[3] = (char_u)(MOUSE_MIDDLE);
+ break;
+ case 4:
+ string[3] = (char_u)(MOUSE_RIGHT);
+ break;
+ default:
+ return;
+ }
+ }
+ string[4] = (char_u)(col + ' ' + 1);
+ string[5] = (char_u)(row + ' ' + 1);
+ oldbuttons = buttons;
+ add_to_input_buf(string, 6);
+ }
+ return;
+}
+#endif /* FEAT_SYSMOUSE */
+
#if defined(FEAT_LIBCALL) || defined(PROTO)
typedef char_u * (*STRPROCSTR)__ARGS((char_u *));
typedef char_u * (*INTPROCSTR)__ARGS((int));
diff -Nur vim71orig/src/term.c vim71/src/term.c
--- vim71orig/src/term.c 2007-05-07 21:39:11.000000000 +0200
+++ vim71/src/term.c 2008-04-07 13:29:07.000000000 +0200
@@ -2108,7 +2108,8 @@
# if ((defined(UNIX) || defined(VMS) || defined(OS2)) \
&& (defined(FEAT_MOUSE_XTERM) || defined(FEAT_MOUSE_DEC) \
- || defined(FEAT_MOUSE_GPM) || defined(FEAT_MOUSE_PTERM))) \
+ || defined(FEAT_MOUSE_GPM) || defined(FEAT_MOUSE_PTERM) \
+ || defined(FEAT_SYSMOUSE))) \
|| defined(PROTO)
void
del_mouse_termcode(n)
diff -Nur vim71orig/src/ui.c vim71/src/ui.c
--- vim71orig/src/ui.c 2007-05-07 21:49:09.000000000 +0200
+++ vim71/src/ui.c 2008-04-07 13:29:07.000000000 +0200
@@ -1600,7 +1600,7 @@
}
#endif
-#if defined(FEAT_GUI) || defined(FEAT_MOUSE_GPM) \
+#if defined(FEAT_GUI) || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE) \
|| defined(FEAT_XCLIPBOARD) || defined(VMS) \
|| defined(FEAT_SNIFF) || defined(FEAT_CLIENTSERVER) \
|| (defined(FEAT_GUI) && (!defined(USE_ON_FLY_SCROLL) \
diff -Nur vim71orig/src/version.c vim71/src/version.c
--- vim71orig/src/version.c 2007-05-12 12:23:44.000000000 +0200
+++ vim71/src/version.c 2008-04-07 13:29:07.000000000 +0200
@@ -335,6 +335,11 @@
# else
"-mouse_gpm",
# endif
+# ifdef FEAT_SYSMOUSE
+ "+mouse_sysmouse",
+# else
+ "-mouse_sysmouse",
+# endif
# ifdef FEAT_MOUSE_JSB
"+mouse_jsbterm",
# else