9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: ori@eigenstate.org, 9front@9front.org
Subject: Re: [9front] rio triple click selection
Date: Sun, 12 Apr 2020 22:15:48 -0700	[thread overview]
Message-ID: <123BD4200452EC42AAE7FF4FEDBEDB19@eigenstate.org> (raw)
In-Reply-To: <C7827F0F34D2D38F9BE060A6F635EF8E@eigenstate.org>

> Sam and Acme should probably get the same treatment.

Here's sam. I also dropped the double click threshold from 1 second(!!).

diff -r d0d202a26d24 sys/src/cmd/sam/mesg.c
--- a/sys/src/cmd/sam/mesg.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/sam/mesg.c	Sun Apr 12 22:15:33 2020 -0700
@@ -54,7 +54,7 @@
 	[Hsnarflen]	"Hsnarflen",
 	[Hack]		"Hack",
 	[Hexit]		"Hexit",
-	[Hplumb]		"Hplumb",
+	[Hplumb]	"Hplumb",
 };
 
 char *tname[] = {
@@ -76,11 +76,12 @@
 	[Tsearch]	"Tsearch",
 	[Tsend]		"Tsend",
 	[Tdclick]	"Tdclick",
+	[Ttclick]	"Ttclick",
 	[Tstartsnarf]	"Tstartsnarf",
 	[Tsetsnarf]	"Tsetsnarf",
 	[Tack]		"Tack",
 	[Texit]		"Texit",
-	[Tplumb]		"Tplumb",
+	[Tplumb]	"Tplumb",
 };
 
 void
@@ -458,9 +459,10 @@
 		break;
 
 	case Tdclick:
+	case Ttclick:
 		f = whichfile(inshort());
 		p1 = inlong();
-		doubleclick(f, p1);
+		stretchsel(f, p1, type == Ttclick);
 		f->tdot.p1 = f->tdot.p2 = p1;
 		telldot(f);
 		outTs(Hunlockfile, f->tag);
diff -r d0d202a26d24 sys/src/cmd/sam/mesg.h
--- a/sys/src/cmd/sam/mesg.h	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/sam/mesg.h	Sun Apr 12 22:15:33 2020 -0700
@@ -1,5 +1,6 @@
 /* VERSION 1 introduces plumbing
 	2 increases SNARFSIZE from 4096 to 32000
+	3 adds a triple click
  */
 #define	VERSION	2
 
@@ -34,6 +35,7 @@
 	Tack,		/* acknowledge Hack */
 	Texit,		/* exit */
 	Tplumb,		/* send plumb message */
+	Ttclick,	/* triple click */
 	TMAX,
 }Tmesg;
 /*
diff -r d0d202a26d24 sys/src/cmd/sam/moveto.c
--- a/sys/src/cmd/sam/moveto.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/sam/moveto.c	Sun Apr 12 22:15:33 2020 -0700
@@ -61,7 +61,7 @@
 }
 
 int
-alnum(int c)
+isalnum(int c)
 {
 	/*
 	 * Hard to get absolutely right.  Use what we know about ASCII
@@ -78,6 +78,19 @@
 }
 
 int
+isspace(Rune c)
+{
+	return c == 0 || c == ' ' || c == '\t' ||
+		c == '\n' || c == '\r' || c == '\v';
+}
+
+int
+inmode(Rune r, int mode)
+{
+	return (mode == 0) ? isalnum(r) : r && !isspace(r);
+}
+
+int
 clickmatch(File *f, int cl, int cr, int dir, Posn *p)
 {
 	int c;
@@ -119,8 +132,15 @@
 	return 0;
 }
 
+/*
+ * Stretches a selection out over current text,
+ * selecting matching range if possible.
+ * If there's no matching range, mode 0 selects
+ * a single alphanumeric region. Mode 1 selects
+ * a non-whitespace region.
+ */
 void
-doubleclick(File *f, Posn p1)
+stretchsel(File *f, Posn p1, int mode)
 {
 	int c, i;
 	Rune *r, *l;
@@ -163,11 +183,11 @@
 	}
 	/* try filling out word to right */
 	p = p1;
-	while(p < f->nc && alnum(filereadc(f, p++)))
+	while(p < f->nc && inmode(filereadc(f, p++), mode))
 		f->dot.r.p2++;
 	/* try filling out word to left */
 	p = p1;
-	while(--p >= 0 && alnum(filereadc(f, p)))
+	while(--p >= 0 && inmode(filereadc(f, p), mode))
 		f->dot.r.p1--;
 }
 
diff -r d0d202a26d24 sys/src/cmd/sam/sam.h
--- a/sys/src/cmd/sam/sam.h	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/sam/sam.h	Sun Apr 12 22:15:33 2020 -0700
@@ -241,7 +241,7 @@
 void	delete(File*);
 void	delfile(File*);
 void	dellist(List*, int);
-void	doubleclick(File*, Posn);
+void	stretchsel(File*, Posn, int);
 void	dprint(char*, ...);
 void	edit(File*, int);
 void	*emalloc(ulong);
diff -r d0d202a26d24 sys/src/cmd/samterm/flayer.c
--- a/sys/src/cmd/samterm/flayer.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/samterm/flayer.c	Sun Apr 12 22:15:33 2020 -0700
@@ -252,19 +252,53 @@
 int
 flselect(Flayer *l)
 {
+	static int clickcount;
+	static Point clickpt = {-10, -10};
+	int dt, dx, dy;
+
+	if(l->visible!=All)
+		flupfront(l);
+	dt = l->click = mousep->msec;
+	dx = abs(mousep->xy.x - clickpt.x);
+	dy = abs(mousep->xy.y - clickpt.y);
+
+	l->click = mousep->msec;
+	clickpt = mousep->xy;
+
+	if(dx < 3 && dy < 3){
+		clickcount++;
+		if(dt >= Clicktime || clickcount >= 3)
+			clickcount = 0;
+		if(clickcount > 0)
+			return clickcount;
+	}
+
+	frselect(&l->f, mousectl);
+	l->p0 = l->f.p0+l->origin, l->p1 = l->f.p1+l->origin;
+	return 0;
+}
+
+#ifdef NOPE
+int
+flselect(Flayer *l)
+{
 	if(l->visible!=All)
 		flupfront(l);
 	if(l->f.p0==l->f.p1)
-		if(mousep->msec-l->click<Clicktime && l->f.p0+l->origin==l->p0 && 
+		if(mousep->msec-l->click >= Clicktime)
+			clickcount = 0;
+		clickcount++;
+		if(clickcount > 0 && l->f.p0+l->origin==l->p0 && 
 			l->f.p0==frcharofpt(&l->f, mousep->xy)){
 			l->click = 0;
-			return 1;
+			return clickcount > 2 ? 2 : clickcount;
 		}
 	l->click = mousep->msec;
 	frselect(&l->f, mousectl);
 	l->p0 = l->f.p0+l->origin, l->p1 = l->f.p1+l->origin;
 	return 0;
 }
+#endif
 
 void
 flsetselect(Flayer *l, long p0, long p1)
diff -r d0d202a26d24 sys/src/cmd/samterm/flayer.h
--- a/sys/src/cmd/samterm/flayer.h	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/samterm/flayer.h	Sun Apr 12 22:15:33 2020 -0700
@@ -5,7 +5,7 @@
 }Vis;
 
 enum{
-	Clicktime=1000,		/* one second */
+	Clicktime=300,		/* milliseconds */
 };
 
 typedef struct Flayer Flayer;
diff -r d0d202a26d24 sys/src/cmd/samterm/main.c
--- a/sys/src/cmd/samterm/main.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/samterm/main.c	Sun Apr 12 22:15:33 2020 -0700
@@ -31,7 +31,7 @@
 void
 threadmain(int argc, char *argv[])
 {
-	int i, got, scr, chord;
+	int i, got, nclick, scr, chord;
 	Text *t;
 	Rectangle r;
 	Flayer *nwhich;
@@ -105,8 +105,12 @@
 					current(nwhich);
 				else{
 					t=(Text *)which->user1;
-					if(flselect(which)){
-						outTsl(Tdclick, t->tag, which->p0);
+					nclick = flselect(which);
+					if(nclick > 0){
+						if(nclick > 1)
+							outTsl(Ttclick, t->tag, which->p0);
+						else
+							outTsl(Tdclick, t->tag, which->p0);
 						t->lock++;
 					}else if(t!=&cmd)
 						outcmd();



  parent reply	other threads:[~2020-04-13  5:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-12 17:19 ori
2020-04-12 17:44 ` [9front] " Stanley Lieber
2020-04-13  5:15 ` ori [this message]
2020-04-25  5:48   ` ori
2020-04-25 12:44     ` Ethan Gardener
2020-04-25 14:00     ` cinap_lenrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=123BD4200452EC42AAE7FF4FEDBEDB19@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).