From owner-svn-src-head@FreeBSD.ORG Thu Dec 19 15:31:21 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6455022B; Thu, 19 Dec 2013 15:31:21 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5037E1ADD; Thu, 19 Dec 2013 15:31:21 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBJFVLR7083115; Thu, 19 Dec 2013 15:31:21 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBJFVKRf083112; Thu, 19 Dec 2013 15:31:20 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201312191531.rBJFVKRf083112@svn.freebsd.org> From: Aleksandr Rybalko Date: Thu, 19 Dec 2013 15:31:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r259615 - head/sys/dev/vt X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Dec 2013 15:31:21 -0000 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