* [9fans] Proof of concept inertial scrolling on macOS with devdraw/acme
@ 2017-02-26 16:54 marius a. eriksen
2017-02-28 7:02 ` Sevki Hasirci
0 siblings, 1 reply; 2+ messages in thread
From: marius a. eriksen @ 2017-02-26 16:54 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
[-- Attachment #1: Type: text/plain, Size: 2273 bytes --]
It’s surprisingly pleasant to use (with a Mac laptop, a Magic Trackpad or
aMagic Mouse)
Demo here: https://www.youtube.com/watch?v=1XJFJ4coS48&feature=youtu.be
commit d782c880d4ca30fcacddfbab298dad82fe8277c3
Author: marius a. eriksen <marius@grailbio.com>
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 != nil && (m.buttons & (8|16))){
+ if((m.buttons >> 2) != 0){
+ winlock(w, 'M');
+ t->eq0 = ~0;
+ xtextscroll(t, m.buttons>>2);
+ winunlock(w);
+ goto Continue;
+ }
+
if(m.buttons & 8)
but = 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 == 0)
+ return;
+
+ if(t->what == Tag){
+ if(n<0)
+ texttype(t, Kscrolloneup);
+ else
+ texttype(t, Kscrollonedown);
+ return;
+ }
+
+ fprint(2, "n=%d\n", n);
+
+ if(n < 0){
+ n = -n;
+ q0 = 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 = 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] == 0)
return;
@@ -1080,11 +1081,22 @@ getmouse(NSEvent *e)
#else
d = [e deltaY];
#endif
+
+
+// fprint(2, "delta: %d\n", (short)d);
+
+ //fprint(2, "d: %f %d\n", d, [e hasPreciseScrollingDeltas]);
+
+ if((short)d==0)
+ return;
+
if(d>0)
in.mscroll = 8;
else
if(d<0)
in.mscroll = 16;
+
+ in.mscroll |= ((short)d)<<1;
break;
case NSMouseMoved:
[-- Attachment #2: Type: text/html, Size: 12037 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [9fans] Proof of concept inertial scrolling on macOS with devdraw/acme
2017-02-26 16:54 [9fans] Proof of concept inertial scrolling on macOS with devdraw/acme marius a. eriksen
@ 2017-02-28 7:02 ` Sevki Hasirci
0 siblings, 0 replies; 2+ messages in thread
From: Sevki Hasirci @ 2017-02-28 7:02 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
[-- Attachment #1: Type: text/plain, Size: 2590 bytes --]
Really cool.
On Sun, 26 Feb 2017 at 17:58, marius a. eriksen <marius@monkey.org> wrote:
> It’s surprisingly pleasant to use (with a Mac laptop, a Magic Trackpad or
> aMagic Mouse)
>
> Demo here: https://www.youtube.com/watch?v=1XJFJ4coS48&feature=youtu.be
>
> commit d782c880d4ca30fcacddfbab298dad82fe8277c3
> Author: marius a. eriksen <marius@grailbio.com>
> 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 != nil && (m.buttons & (8|16))){
> + if((m.buttons >> 2) != 0){
> + winlock(w, 'M');
> + t->eq0 = ~0;
> + xtextscroll(t, m.buttons>>2);
> + winunlock(w);
> + goto Continue;
> + }
> +
> if(m.buttons & 8)
> but = 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 == 0)
> + return;
> +
> + if(t->what == Tag){
> + if(n<0)
> + texttype(t, Kscrolloneup);
> + else
> + texttype(t, Kscrollonedown);
> + return;
> + }
> +
> + fprint(2, "n=%d\n", n);
> +
> + if(n < 0){
> + n = -n;
> + q0 = 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 = 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] == 0)
> return;
> @@ -1080,11 +1081,22 @@ getmouse(NSEvent *e)
> #else
> d = [e deltaY];
> #endif
> +
> +
> +// fprint(2, "delta: %d\n", (short)d);
> +
> + //fprint(2, "d: %f %d\n", d, [e hasPreciseScrollingDeltas]);
> +
> + if((short)d==0)
> + return;
> +
> if(d>0)
> in.mscroll = 8;
> else
> if(d<0)
> in.mscroll = 16;
> +
> + in.mscroll |= ((short)d)<<1;
> break;
>
> case NSMouseMoved:
>
> --
-s
[-- Attachment #2: Type: text/html, Size: 16523 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-02-28 7:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-26 16:54 [9fans] Proof of concept inertial scrolling on macOS with devdraw/acme marius a. eriksen
2017-02-28 7:02 ` Sevki Hasirci
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).