From owner-svn-src-head@FreeBSD.ORG Fri Sep 12 14:14:51 2014 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 22BBC55E; Fri, 12 Sep 2014 14:14:51 +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)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0389D6C1; Fri, 12 Sep 2014 14:14:51 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8CEEonU064615; Fri, 12 Sep 2014 14:14:50 GMT (envelope-from ray@FreeBSD.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8CEEora064614; Fri, 12 Sep 2014 14:14:50 GMT (envelope-from ray@FreeBSD.org) Message-Id: <201409121414.s8CEEora064614@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ray set sender to ray@FreeBSD.org using -f From: Aleksandr Rybalko Date: Fri, 12 Sep 2014 14:14:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271464 - 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.18-1 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: Fri, 12 Sep 2014 14:14:51 -0000 Author: ray Date: Fri Sep 12 14:14:50 2014 New Revision: 271464 URL: http://svnweb.freebsd.org/changeset/base/271464 Log: Switch vt(4) to traditional behaviour with copy-paste same as syscons(4) do. Reviewed by: dumbbell (as D755) MFC after: 1 week Modified: head/sys/dev/vt/vt_core.c Modified: head/sys/dev/vt/vt_core.c ============================================================================== --- head/sys/dev/vt/vt_core.c Fri Sep 12 14:07:20 2014 (r271463) +++ head/sys/dev/vt/vt_core.c Fri Sep 12 14:14:50 2014 (r271464) @@ -162,6 +162,7 @@ static int vt_late_window_switch(struct static int vt_proc_alive(struct vt_window *); static void vt_resize(struct vt_device *); static void vt_update_static(void *); +static void vt_mouse_paste(); SET_DECLARE(vt_drv_set, struct vt_driver); @@ -176,10 +177,14 @@ static struct vt_device vt_consdev = { .vd_flags = VDF_INVALID, .vd_windows = { [VT_CONSWINDOW] = &vt_conswindow, }, .vd_curwindow = &vt_conswindow, - .vd_markedwin = NULL, .vd_kbstate = 0, #ifndef SC_NO_CUTPASTE + .vd_pastebuf = { + .vpb_buf = NULL, + .vpb_bufsz = 0, + .vpb_len = 0 + }, .vd_mcursor = &vt_default_mouse_pointer, .vd_mcursor_fg = TC_WHITE, .vd_mcursor_bg = TC_BLACK, @@ -508,7 +513,7 @@ vt_machine_kbdevent(int c) case SPCLKEY | PASTE: /* kbdmap(5) keyword `paste`. */ #ifndef SC_NO_CUTPASTE /* Insert text from cut-paste buffer. */ - /* TODO */ + vt_mouse_paste(); #endif break; case SPCLKEY | PDWN: /* kbdmap(5) keyword `pdwn`. */ @@ -1576,7 +1581,7 @@ vt_mouse_terminput_button(struct vt_devi mouseb[4] = '!' + x; mouseb[5] = '!' + y; - for (i = 0; i < sizeof(mouseb); i++ ) + for (i = 0; i < sizeof(mouseb); i++) terminal_input_char(vw->vw_terminal, mouseb[i]); } @@ -1614,6 +1619,23 @@ vt_mouse_terminput(struct vt_device *vd, } } +static void +vt_mouse_paste() +{ + term_char_t *buf; + int i, len; + + len = VD_PASTEBUFLEN(main_vd); + buf = VD_PASTEBUF(main_vd); + len /= sizeof(term_char_t); + for (i = 0; i < len; i++) { + if (buf[i] == '\0') + continue; + terminal_input_char(main_vd->vd_curwindow->vw_terminal, + buf[i]); + } +} + void vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel) { @@ -1621,8 +1643,7 @@ vt_mouse_event(int type, int x, int y, i struct vt_window *vw; struct vt_font *vf; term_pos_t size; - term_char_t *buf; - int i, len, mark; + int len, mark; vd = main_vd; vw = vd->vd_curwindow; @@ -1665,17 +1686,10 @@ vt_mouse_event(int type, int x, int y, i vd->vd_mx = x; vd->vd_my = y; - if ((vd->vd_mstate & MOUSE_BUTTON1DOWN) && - (vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE, - vd->vd_mx / vf->vf_width, - vd->vd_my / vf->vf_height) == 1)) { - - /* - * We have something marked to copy, so update pointer - * to window with selection. - */ - vd->vd_markedwin = vw; - } + if (vd->vd_mstate & MOUSE_BUTTON1DOWN) + vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE, + vd->vd_mx / vf->vf_width, + vd->vd_my / vf->vf_height); vt_resume_flush_timer(vw->vw_device, 0); return; /* Done */ @@ -1708,27 +1722,7 @@ vt_mouse_event(int type, int x, int y, i case 0: /* up */ break; default: - if (vd->vd_markedwin == NULL) - return; - /* Get current selecton size in bytes. */ - len = vtbuf_get_marked_len(&vd->vd_markedwin->vw_buf); - if (len <= 0) - return; - - buf = malloc(len, M_VT, M_WAITOK | M_ZERO); - /* Request copy/paste buffer data, no more than `len' */ - vtbuf_extract_marked(&vd->vd_markedwin->vw_buf, buf, - len); - - len /= sizeof(term_char_t); - for (i = 0; i < len; i++ ) { - if (buf[i] == '\0') - continue; - terminal_input_char(vw->vw_terminal, buf[i]); - } - - /* Done, so cleanup. */ - free(buf, M_VT); + vt_mouse_paste(); break; } return; /* Done */ @@ -1761,8 +1755,38 @@ vt_mouse_event(int type, int x, int y, i * We have something marked to copy, so update pointer to * window with selection. */ - vd->vd_markedwin = vw; vt_resume_flush_timer(vw->vw_device, 0); + + switch (mark) { + case VTB_MARK_END: + case VTB_MARK_WORD: + case VTB_MARK_ROW: + case VTB_MARK_EXTEND: + break; + default: + /* Other types of mark do not require to copy data. */ + return; + } + + /* Get current selection size in bytes. */ + len = vtbuf_get_marked_len(&vw->vw_buf); + if (len <= 0) + return; + + /* Reallocate buffer only if old one is too small. */ + if (len > VD_PASTEBUFSZ(vd)) { + VD_PASTEBUF(vd) = realloc(VD_PASTEBUF(vd), len, M_VT, + M_WAITOK | M_ZERO); + /* Update buffer size. */ + VD_PASTEBUFSZ(vd) = len; + } + /* Request copy/paste buffer data, no more than `len' */ + vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd), + VD_PASTEBUFSZ(vd)); + + VD_PASTEBUFLEN(vd) = len; + + /* XXX VD_PASTEBUF(vd) have to be freed on shutdown/unload. */ } }