[dev] [PATCH 8/8] Add enumeration for sel.mode

From: noname <noname_AT_inventati.org>
Date: Fri, 1 May 2015 17:13:13 +0000

This patch also prevents sel.mode from increasing beyond 2. It is almost
impossible, but sel.mode may overflow if mouse is moved around for too
long while selecting.
---
 st.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/st.c b/st.c
index 43fdbb3..9b1771d 100644
--- a/st.c
+++ b/st.c
_AT_@ -162,6 +162,12 @@ enum window_state {
 	WIN_FOCUSED = 2
 };
 
+enum selection_mode {
+	SEL_IDLE = 0,
+	SEL_EMPTY = 1,
+	SEL_READY = 2
+};
+
 enum selection_type {
 	SEL_REGULAR = 1,
 	SEL_RECTANGULAR = 2
_AT_@ -643,7 +649,7 @@ void
 selinit(void) {
 	memset(&sel.tclick1, 0, sizeof(sel.tclick1));
 	memset(&sel.tclick2, 0, sizeof(sel.tclick2));
-	sel.mode = 0;
+	sel.mode = SEL_IDLE;
 	sel.ob.x = -1;
 	sel.primary = NULL;
 	sel.clipboard = NULL;
_AT_@ -874,7 +880,7 @@ bpress(XEvent *e) {
 
 		/* Clear previous selection, logically and visually. */
 		selclear(NULL);
-		sel.mode = 1;
+		sel.mode = SEL_EMPTY;
 		sel.type = SEL_REGULAR;
 		sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
 		sel.oe.y = sel.ob.y = y2row(e->xbutton.y);
_AT_@ -897,7 +903,7 @@ bpress(XEvent *e) {
 		 * make clicks visible
 		 */
 		if(sel.snap != 0) {
-			sel.mode++;
+			sel.mode = SEL_READY;
 			tsetdirt(sel.nb.y, sel.ne.y);
 		}
 		sel.tclick2 = sel.tclick1;
_AT_@ -1119,13 +1125,12 @@ brelease(XEvent *e) {
 	if(e->xbutton.button == Button2) {
 		selpaste(NULL);
 	} else if(e->xbutton.button == Button1) {
-		if(sel.mode < 2) {
-			selclear(NULL);
-		} else {
+		if(sel.mode == SEL_READY) {
 			getbuttoninfo(e);
 			selcopy(e->xbutton.time);
-		}
-		sel.mode = 0;
+		} else
+			selclear(NULL);
+		sel.mode = SEL_IDLE;
 		tsetdirt(sel.nb.y, sel.ne.y);
 	}
 }
_AT_@ -1142,7 +1147,7 @@ bmotion(XEvent *e) {
 	if(!sel.mode)
 		return;
 
-	sel.mode++;
+	sel.mode = SEL_READY;
 	oldey = sel.oe.y;
 	oldex = sel.oe.x;
 	oldsby = sel.nb.y;
-- 
1.8.4
Received on Fri May 01 2015 - 19:13:13 CEST

This archive was generated by hypermail 2.3.0 : Fri May 01 2015 - 19:24:08 CEST