aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2018-02-21 23:29:41 -0600
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:53:24 -0600
commitbcb5d3adbe57ead05a829e5144c2ba1dc465865f (patch)
treed72e99c54044e02063924f2416ceb9760c2141ec /st.c
parent5683b1f80c5ac274adf98517ce2217b4d4896243 (diff)
downloadst-bcb5d3adbe57ead05a829e5144c2ba1dc465865f.tar.gz
st-bcb5d3adbe57ead05a829e5144c2ba1dc465865f.tar.bz2
st-bcb5d3adbe57ead05a829e5144c2ba1dc465865f.zip
Move terminal-related selection logic into st.c
The front-end determines information about mouse clicks and motion, and the terminal handles the actual selection start/extend/dirty logic by row and column. While we're in the neighborhood, we'll also rename getbuttoninfo() to mousesel() which is, at least, less wrong. Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Diffstat (limited to 'st.c')
-rw-r--r--st.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/st.c b/st.c
index ea0726c..21cba9e 100644
--- a/st.c
+++ b/st.c
@@ -140,6 +140,7 @@ static void tscrollup(int, int);
static void tscrolldown(int, int);
static void tsetattr(int *, int);
static void tsetchar(Rune, Glyph *, int, int);
+static void tsetdirt(int, int);
static void tsetscroll(int, int);
static void tswapscreen(void);
static void tsetmode(int, int, int *, int);
@@ -385,6 +386,42 @@ tlinelen(int y)
}
void
+selstart(int col, int row, int snap)
+{
+ selclear();
+ sel.mode = SEL_EMPTY;
+ sel.type = SEL_REGULAR;
+ sel.snap = snap;
+ sel.oe.x = sel.ob.x = col;
+ sel.oe.y = sel.ob.y = row;
+ selnormalize();
+
+ if (sel.snap != 0)
+ sel.mode = SEL_READY;
+ tsetdirt(sel.nb.y, sel.ne.y);
+}
+
+void
+selextend(int col, int row, int type)
+{
+ int oldey, oldex, oldsby, oldsey, oldtype;
+ oldey = sel.oe.y;
+ oldex = sel.oe.x;
+ oldsby = sel.nb.y;
+ oldsey = sel.ne.y;
+ oldtype = sel.type;
+
+ sel.alt = IS_SET(MODE_ALTSCREEN);
+ sel.oe.x = col;
+ sel.oe.y = row;
+ selnormalize();
+ sel.type = type;
+
+ if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
+ tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
+}
+
+void
selnormalize(void)
{
int i;