Hello,

        When the selection is woner by another window we sholud remove the
highlight, because in other case it creates some confusion to the user.

Best regards.
>From 6c7267744f8a1effeda813d5c0105247e46b19a5 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Wed, 5 Sep 2012 21:07:03 +0200
Subject: [PATCH] Unhighlight selection when selection is owner by other
 window

st marks the active selection using reverse colors in the box selection, but
once that another window becomes owner of the selection, it is very
confusing that st keeps highlight the old selection. Usually terminal
emulators remove the highlight when it is not valid anymore.

X sends a SelectionClear event in this situation, so we only have to add a
callback which unhighlight the selectin box.
---
 st.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/st.c b/st.c
index cf329fd..fbf5a46 100644
--- a/st.c
+++ b/st.c
@@ -310,6 +310,7 @@ static void brelease(XEvent *);
 static void bpress(XEvent *);
 static void bmotion(XEvent *);
 static void selnotify(XEvent *);
+static void selclear(XEvent *);
 static void selrequest(XEvent *);
 
 static void selinit(void);
@@ -335,6 +336,7 @@ static void (*handler[LASTEvent])(XEvent *) = {
 	[MotionNotify] = bmotion,
 	[ButtonPress] = bpress,
 	[ButtonRelease] = brelease,
+	[SelectionClear] = selclear,
 	[SelectionNotify] = selnotify,
 	[SelectionRequest] = selrequest,
 };
@@ -611,6 +613,13 @@ selpaste() {
 	XConvertSelection(xw.dpy, XA_PRIMARY, sel.xtarget, XA_PRIMARY, xw.win, CurrentTime);
 }
 
+void selclear(XEvent *e) {
+	if(sel.bx == -1)
+		return;
+	sel.bx = -1;
+	tsetdirt(sel.b.y, sel.e.y);
+}
+
 void
 selrequest(XEvent *e) {
 	XSelectionRequestEvent *xsre;
-- 
1.7.10.4

Reply via email to