Author: ray
Date: Thu Dec 19 15:31:20 2013
New Revision: 259615
URL: http://svnweb.freebsd.org/changeset/base/259615

Log:
  Enable mouse support for terminal clients (like dialog(1)).
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/dev/vt/vt.h
  head/sys/dev/vt/vt_core.c
  head/sys/dev/vt/vt_sysmouse.c

Modified: head/sys/dev/vt/vt.h
==============================================================================
--- head/sys/dev/vt/vt.h        Thu Dec 19 13:44:07 2013        (r259614)
+++ head/sys/dev/vt/vt.h        Thu Dec 19 15:31:20 2013        (r259615)
@@ -412,7 +412,7 @@ int          vtfont_load(vfnt_t *f, struct vt_f
 /* Sysmouse. */
 void sysmouse_process_event(mouse_info_t *mi);
 #ifndef SC_NO_CUTPASTE
-void vt_mouse_event(int type, int x, int y, int event, int cnt);
+void vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel);
 void vt_mouse_state(int show);
 #endif
 #define        VT_MOUSE_SHOW 1

Modified: head/sys/dev/vt/vt_core.c
==============================================================================
--- head/sys/dev/vt/vt_core.c   Thu Dec 19 13:44:07 2013        (r259614)
+++ head/sys/dev/vt/vt_core.c   Thu Dec 19 15:31:20 2013        (r259615)
@@ -1120,8 +1120,68 @@ finish_vt_acq(struct vt_window *vw)
 }
 
 #ifndef SC_NO_CUTPASTE
+static void
+vt_mouse_terminput_button(struct vt_device *vd, int button)
+{
+       struct vt_window *vw;
+       struct vt_font *vf;
+       char mouseb[6] = "\x1B[M";
+       int i, x, y;
+
+       vw = vd->vd_curwindow;
+       vf = vw->vw_font;
+
+       /* Translate to char position. */
+       x = vd->vd_mx / vf->vf_width;
+       y = vd->vd_my / vf->vf_height;
+       /* Avoid overflow. */
+       x = MIN(x, 255 - '!');
+       y = MIN(y, 255 - '!');
+
+       mouseb[3] = ' ' + button;
+       mouseb[4] = '!' + x;
+       mouseb[5] = '!' + y;
+
+       for (i = 0; i < sizeof(mouseb); i++ )
+               terminal_input_char(vw->vw_terminal, mouseb[i]);
+}
+
+static void
+vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event,
+    int cnt)
+{
+
+       switch (type) {
+       case MOUSE_BUTTON_EVENT:
+               if (cnt > 0) {
+                       /* Mouse button pressed. */
+                       if (event & MOUSE_BUTTON1DOWN)
+                               vt_mouse_terminput_button(vd, 0);
+                       if (event & MOUSE_BUTTON2DOWN)
+                               vt_mouse_terminput_button(vd, 1);
+                       if (event & MOUSE_BUTTON3DOWN)
+                               vt_mouse_terminput_button(vd, 2);
+               } else {
+                       /* Mouse button released. */
+                       vt_mouse_terminput_button(vd, 3);
+               }
+               break;
+#ifdef notyet
+       case MOUSE_MOTION_EVENT:
+               if (mouse->u.data.z < 0) {
+                       /* Scroll up. */
+                       sc_mouse_input_button(vd, 64);
+               } else if (mouse->u.data.z > 0) {
+                       /* Scroll down. */
+                       sc_mouse_input_button(vd, 65);
+               }
+               break;
+#endif
+       }
+}
+
 void
-vt_mouse_event(int type, int x, int y, int event, int cnt)
+vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
 {
        struct vt_device *vd;
        struct vt_window *vw;
@@ -1146,6 +1206,9 @@ vt_mouse_event(int type, int x, int y, i
         * under mouse pointer when nothing changed.
         */
 
+       if (mlevel > 0)
+               vt_mouse_terminput(vd, type, x, y, event, cnt);
+
        switch (type) {
        case MOUSE_ACTION:
        case MOUSE_MOTION_EVENT:

Modified: head/sys/dev/vt/vt_sysmouse.c
==============================================================================
--- head/sys/dev/vt/vt_sysmouse.c       Thu Dec 19 13:44:07 2013        
(r259614)
+++ head/sys/dev/vt/vt_sysmouse.c       Thu Dec 19 15:31:20 2013        
(r259615)
@@ -192,7 +192,8 @@ sysmouse_process_event(mouse_info_t *mi)
 
 #ifndef SC_NO_CUTPASTE
        mtx_unlock(&sysmouse_lock);
-       vt_mouse_event(mi->operation, x, y, mi->u.event.id, mi->u.event.value);
+       vt_mouse_event(mi->operation, x, y, mi->u.event.id, mi->u.event.value,
+           sysmouse_level);
        return;
 #endif
 
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to