From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 References: In-Reply-To: From: Sevki Hasirci Date: Tue, 28 Feb 2017 07:02:26 +0000 Message-ID: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=001a1142b0eeef6f3c054991c7ab Subject: Re: [9fans] Proof of concept inertial scrolling on macOS with devdraw/acme Topicbox-Message-UUID: b60d1144-ead9-11e9-9d60-3106f5b1d025 --001a1142b0eeef6f3c054991c7ab Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Really cool. On Sun, 26 Feb 2017 at 17:58, marius a. eriksen wrote: > It=E2=80=99s surprisingly pleasant to use (with a Mac laptop, a Magic Tra= ckpad or > aMagic Mouse) > > Demo here: https://www.youtube.com/watch?v=3D1XJFJ4coS48&feature=3Dyoutu.= be > > commit d782c880d4ca30fcacddfbab298dad82fe8277c3 > Author: marius a. eriksen > Date: Sat Feb 25 21:48:50 2017 -0800 > > devdraw/acme: support for inertial scrolling on macOS. > > diff --git a/src/cmd/acme/acme.c b/src/cmd/acme/acme.c > index b471a29..d84322f 100644 > --- a/src/cmd/acme/acme.c > +++ b/src/cmd/acme/acme.c > @@ -614,6 +614,14 @@ mousethread(void *v) > } > /* scroll buttons, wheels, etc. */ > if(w !=3D nil && (m.buttons & (8|16))){ > + if((m.buttons >> 2) !=3D 0){ > + winlock(w, 'M'); > + t->eq0 =3D ~0; > + xtextscroll(t, m.buttons>>2); > + winunlock(w); > + goto Continue; > + } > + > if(m.buttons & 8) > but =3D Kscrolloneup; > else > diff --git a/src/cmd/acme/text.c b/src/cmd/acme/text.c > index 7634d92..72b29c2 100644 > --- a/src/cmd/acme/text.c > +++ b/src/cmd/acme/text.c > @@ -653,6 +653,35 @@ textcomplete(Text *t) > return rp; > } > > +void > +xtextscroll(Text *t, int n) > +{ > + uint q0; > + > + > + if(n =3D=3D 0) > + return; > + > + if(t->what =3D=3D Tag){ > + if(n<0) > + texttype(t, Kscrolloneup); > + else > + texttype(t, Kscrollonedown); > + return; > + } > + > + fprint(2, "n=3D%d\n", n); > + > + if(n < 0){ > + n =3D -n; > + q0 =3D t->org+frcharofpt(&t->fr, Pt(t->fr.r.min.x, > t->fr.r.min.y+n*t->fr.font->height)); > + textsetorigin(t, q0, TRUE); > + }else{ > + q0 =3D textbacknl(t, t->org, n); > + textsetorigin(t, q0, TRUE); > + } > +} > + > void > texttype(Text *t, Rune r) > { > diff --git a/src/cmd/devdraw/cocoa-screen.m > b/src/cmd/devdraw/cocoa-screen.m > index 100cdd5..b83a3ff 100644 > --- a/src/cmd/devdraw/cocoa-screen.m > +++ b/src/cmd/devdraw/cocoa-screen.m > @@ -1044,7 +1044,8 @@ static void > getmouse(NSEvent *e) > { > float d; > - int b, m; > + int b, m, i; > + static int accum; > > if([WIN isKeyWindow] =3D=3D 0) > return; > @@ -1080,11 +1081,22 @@ getmouse(NSEvent *e) > #else > d =3D [e deltaY]; > #endif > + > + > +// fprint(2, "delta: %d\n", (short)d); > + > + //fprint(2, "d: %f %d\n", d, [e hasPreciseScrollingDeltas]); > + > + if((short)d=3D=3D0) > + return; > + > if(d>0) > in.mscroll =3D 8; > else > if(d<0) > in.mscroll =3D 16; > + > + in.mscroll |=3D ((short)d)<<1; > break; > > case NSMouseMoved: > > -- -s --001a1142b0eeef6f3c054991c7ab Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Really cool.
On Sun, 26 Feb= 2017 at 17:58, marius a. eriksen <= marius@monkey.org> wrote:
It=E2=80=99s surprisingly pleasant to use (= with a Mac laptop, a Magic Trackpad or aMagic Mouse)


commit d782c880d4ca30fcacddfbab298dad82fe8277c3
Author: ma= rius a. eriksen <marius@grailbio.com>
Date: =C2=A0 Sat Feb 25= 21:48:50 2017 -0800

=C2=A0 =C2=A0 devdraw/acm= e: support for inertial scrolling on macOS.

di= ff --git a/src/cmd/acme/acme.c b/src/cmd/acme/acme.c
index b471a29..d8432= 2f 100644
--- a/src/cmd/acme/acme.c
+++ b/src/cmd/acme/acme.c
@@ -614= ,6 +614,14 @@ mousethread(void *v)
=C2=A0 }
=C2=A0 /* scroll buttons, wheels, et= c. */
=C2=A0 if(w !=3D nil && (m= .buttons & (8|16))){
+ if((m.button= s >> 2) !=3D 0){
+ winlock(w, &#= 39;M');
+ t->eq0 =3D ~0;
=
+ xtextscroll(t, m.buttons>>2);
=
+ winunlock(w);
+= goto Continue;
+ }
+
= =C2=A0 if(m.buttons & 8)
=C2=A0 but =3D Kscrolloneup;
=C2=A0 else
diff --git a/src/cmd/acme/text.c b/src/cmd/a= cme/text.c
index 7634d92..72b29c2 100644
--- a/src/cmd/acme/text.c
= +++ b/src/cmd/acme/text.c
@@ -653,6 +653,35 @@ textcomplete(Text *t)
= =C2=A0 return rp;
=C2=A0}
=C2=A0
<= div style=3D"font-family:helvetica;font-size:12px" class=3D"gmail_msg">+voi= d
+xtextscroll(Text *t, int n)
+{
+ ui= nt q0;
+
+
+ if(n =3D=3D 0)
+ return;
+
+ = if(t->what =3D=3D Tag){
+ if(n<0)
+ texttype(t, Kscrolloneup);
+ else
+ texttype(= t, Kscrollonedown);
+ return;
+ }
+
+ fprint(2, "n=3D%d\n", n);
+
+ if(n < 0){
+ n= =3D -n;
+ q0 =3D t->org+frcharofpt(&a= mp;t->fr, Pt(t->fr.r.min.x, t->fr.r.min.y+n*t->fr.font->heig= ht));
+ textsetorigin(t, q0, TRUE);
=
+ }else{
+ q0= =3D textbacknl(t, t->org, n);
+ texts= etorigin(t, q0, TRUE);
+ }
+}
+
<= div style=3D"font-family:helvetica;font-size:12px" class=3D"gmail_msg">=C2= =A0void
=C2=A0texttype(Text *t, Rune r)
=C2=A0{
diff --git a/src/cmd/= devdraw/cocoa-screen.m b/src/cmd/devdraw/cocoa-screen.m
index 100cdd5..b8= 3a3ff 100644
--- a/src/cmd/devdraw/cocoa-screen.m
+++ b/src/cmd/devdraw= /cocoa-screen.m
@@ -1044,7 +1044,8 @@ static void
=C2=A0getmouse(NSEven= t *e)
=C2=A0{
=C2=A0 float d;
- int b, m;
+ int b= , m, i;
+ static int accum;
=C2=A0
=
=C2= =A0 if([WIN isKeyWindow] =3D=3D 0)
=C2=A0<= span class=3D"m_7410606785244844748inbox-Apple-tab-span gmail_msg" style=3D= "white-space:pre-wrap"> return;
@@ -1080,11 +1081,22 @@ getmouse(= NSEvent *e)
=C2=A0#else
=C2=A0 d =3D [= e deltaY];
=C2=A0#endif
+
+
<= div style=3D"font-family:helvetica;font-size:12px" class=3D"gmail_msg">+//<= span class=3D"m_7410606785244844748inbox-Apple-tab-span gmail_msg" style=3D= "white-space:pre-wrap"> fprint(2, "delta: %d\n", (short)d= );
+
+ //fprint(2, "d: %f %d\n&quo= t;, d, [e hasPreciseScrollingDeltas]);
+ =
+ if((short)d=3D=3D0)=C2=A0
+ return;
+
=C2=A0 if(d>0)
=C2=A0 in.mscroll =3D 8;
=C2=A0 else
=C2=A0 if(d<0)
=C2=A0 in.mscroll = =3D 16;
+
+ in.mscroll |=3D ((short)d)= <<1;
=C2=A0 break;
=C2=A0
=
=C2= =A0 case NSMouseMoved:

--
-s
--001a1142b0eeef6f3c054991c7ab--