svn commit: r257971 - user/ed/newcons/sys/dev/vt

Aleksandr Rybalko ray at FreeBSD.org
Mon Nov 11 11:50:18 UTC 2013


Author: ray
Date: Mon Nov 11 11:50:17 2013
New Revision: 257971
URL: http://svnweb.freebsd.org/changeset/base/257971

Log:
  Add mouse related vtbuf operations.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  user/ed/newcons/sys/dev/vt/vt_buf.c

Modified: user/ed/newcons/sys/dev/vt/vt_buf.c
==============================================================================
--- user/ed/newcons/sys/dev/vt/vt_buf.c	Mon Nov 11 11:48:24 2013	(r257970)
+++ user/ed/newcons/sys/dev/vt/vt_buf.c	Mon Nov 11 11:50:17 2013	(r257971)
@@ -46,6 +46,9 @@ static MALLOC_DEFINE(M_VTBUF, "vtbuf", "
 
 #define	VTBUF_LOCK(vb)		mtx_lock_spin(&(vb)->vb_lock)
 #define	VTBUF_UNLOCK(vb)	mtx_unlock_spin(&(vb)->vb_lock)
+
+#define POS_INDEX(vb, c, r) ((r) * (vb)->vb_scr_size.tp_col + (c))
+
 /*
  * line4
  * line5 <--- curroffset (terminal output to that line)
@@ -127,6 +130,21 @@ vthistory_getpos(const struct vt_buf *vb
 	*offset = vb->vb_roffset;
 }
 
+int
+vtbuf_iscursor(struct vt_buf *vb, int row, int col)
+{
+	if ((vb->vb_flags & VBF_CURSOR) && (vb->vb_cursor.tp_row == row) &&
+	    (vb->vb_cursor.tp_col == col))
+		return (1);
+
+	if ((POS_INDEX(vb, vb->vb_mark_start.tp_col, vb->vb_mark_start.tp_row) <
+	    POS_INDEX(vb, col, row)) && (POS_INDEX(vb, col, row) <=
+	    POS_INDEX(vb, vb->vb_mark_start.tp_col, vb->vb_mark_start.tp_row)))
+		return (1);
+
+	return (0);
+}
+
 static inline uint64_t
 vtbuf_dirty_axis(unsigned int begin, unsigned int end)
 {
@@ -463,6 +481,77 @@ vtbuf_cursor_position(struct vt_buf *vb,
 }
 
 void
+vtbuf_mouse_cursor_position(struct vt_buf *vb, int col, int row)
+{
+	term_rect_t area;
+
+	area.tr_begin.tp_row = MAX(row - 1, 0);
+	area.tr_begin.tp_col = MAX(col - 1, 0);
+	area.tr_end.tp_row = MIN(row + 2, vb->vb_scr_size.tp_row);
+	area.tr_end.tp_col = MIN(col + 2, vb->vb_scr_size.tp_col);
+	vtbuf_dirty(vb, &area);
+}
+
+void
+vtbuf_set_mark(struct vt_buf *vb, int type, int col, int row)
+{
+	term_rect_t area;
+	vt_axis_t tmp;
+
+	switch (type) {
+	case VTB_MARK_END:
+	case VTB_MARK_EXTEND:
+		vb->vb_mark_end.tp_col = col;
+		vb->vb_mark_end.tp_row = row;
+		break;
+	case VTB_MARK_START:
+		vb->vb_mark_start.tp_col = col;
+		vb->vb_mark_start.tp_row = row;
+		/* Start again, so clear end point. */
+		vb->vb_mark_end.tp_col = 0;
+		vb->vb_mark_end.tp_row = 0;
+		break;
+	case VTB_MARK_WORD:
+		vb->vb_mark_start.tp_col = 0; /* XXX */
+		vb->vb_mark_end.tp_col = 10; /* XXX */
+		vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row = row;
+		break;
+	case VTB_MARK_ROW:
+		vb->vb_mark_start.tp_col = 0;
+		vb->vb_mark_end.tp_col = vb->vb_scr_size.tp_col;
+		vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row = row;
+		break;
+	}
+
+	/* Swap start and end if start > end. */
+	if (POS_INDEX(vb, vb->vb_mark_start.tp_col, vb->vb_mark_start.tp_row) >
+	    POS_INDEX(vb, vb->vb_mark_end.tp_col, vb->vb_mark_end.tp_row)) {
+		tmp = vb->vb_mark_start.tp_col;
+		vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col;
+		vb->vb_mark_end.tp_col = tmp;
+		tmp = vb->vb_mark_start.tp_row;
+		vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row;
+		vb->vb_mark_end.tp_row = tmp;
+	}
+
+	/* Notify renderer to update marked region. */
+	if (vb->vb_mark_start.tp_col || vb->vb_mark_end.tp_col ||
+	    vb->vb_mark_start.tp_row || vb->vb_mark_end.tp_row) {
+
+		area.tr_begin.tp_col = 0;
+		area.tr_begin.tp_row = MIN(vb->vb_mark_start.tp_row,
+		    vb->vb_mark_end.tp_row);
+
+		area.tr_end.tp_col = vb->vb_scr_size.tp_col;
+		area.tr_end.tp_row = MAX(vb->vb_mark_start.tp_row,
+		    vb->vb_mark_end.tp_row);
+
+		vtbuf_dirty(vb, &area);
+	}
+
+}
+
+void
 vtbuf_cursor_visibility(struct vt_buf *vb, int yes)
 {
 	int oflags, nflags;


More information about the svn-src-user mailing list