experimental force touch support in devdraw

174 views
Skip to first unread message

marius eriksen

unread,
Nov 4, 2015, 12:45:28 AM11/4/15
to plan9port-dev
This is completely experimental, but I’ve found it very handy:

- force-touching alone simulates a B3 click
- force-touching while also holding B2 (e.g., via the option key) becomes a 2-1 chord

-m.

diff --git a/src/cmd/devdraw/cocoa-screen.m b/src/cmd/devdraw/cocoa-screen.m
index fc73814..f65f653 100644
--- a/src/cmd/devdraw/cocoa-screen.m
+++ b/src/cmd/devdraw/cocoa-screen.m
@@ -37,8 +37,12 @@ int usegestures = 0;
int useliveresizing = 0;
int useoldfullscreen = 0;
int usebigarrow = 0;
+int pressurestage = 0;
+int stagebuttons = 0;

static void setprocname(const char*);
+static void sendclick(int);
+

/*
* By default, devdraw uses retina displays.
@@ -786,6 +790,35 @@ static void updatecursor(void);
{
gettouch(e, NSTouchPhaseCancelled);
}
+
+- (void)pressureChangeWithEvent:(NSEvent *)e
+{
+ if(pressurestage == 1 && e.stage == 2){
+ switch(stagebuttons = in.mbuttons){
+ case 1:
+ in.mbuttons = 0;
+ sendmouse();
+ in.mbuttons = 4;
+ sendmouse();
+ break;
+ case 2:
+ in.mbuttons |= 1;
+ sendmouse();
+ default:
+ break;
+ }
+ }else if(pressurestage == 2 && e.stage == 1){
+ if(stagebuttons != 0){
+ in.mbuttons = 0;
+ sendmouse();
+ in.mbuttons = stagebuttons;
+ }
+ stagebuttons = 0;
+ }
+
+ pressurestage = e.stage;
+}
+
@end

static int keycvt[] =
@@ -1057,7 +1090,6 @@ getgesture(NSEvent *e)
}
}

-static void sendclick(int);

static uint
msec(void)
@@ -1072,7 +1104,7 @@ gettouch(NSEvent *e, int type)
static uint taptime;
NSSet *set;
int p;
-
+
switch(type){
case NSTouchPhaseBegan:
p = NSTouchPhaseTouching;
@@ -1126,6 +1158,7 @@ sendmouse(void)
mouserect = Rect(0, 0, size.width, size.height);

b = in.kbuttons | in.mbuttons | in.mscroll;
+
mousetrack(in.mpos.x, in.mpos.y, b, msec());
in.mscroll = 0;
}

Russ Cox

unread,
Nov 9, 2015, 3:57:41 PM11/9/15
to Marius Eriksen, plan9port-dev
Thanks! 

BTW I've seen various redraw artifacts with devdraw on El Capitan. (Window not drawn initially, label in 9terms doesn't seem to like being updated longer than original label, maybe others.) Since you seem to understand the language that code is written in, any ideas? :-)

Thanks again.
Russ




--

---
You received this message because you are subscribed to the Google Groups "plan9port-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plan9port-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sqweek

unread,
Nov 10, 2015, 8:33:35 PM11/10/15
to Russ Cox, Marius Eriksen, plan9port-dev
Regarding the label issue, it looks like cocoa-screen.m isn't calling
[NSWindow setTitle] on the main thread, which Capitan is apparently
more strict about[1]. I'm off to work now; I can prepare a patch later
but I don't have a real OSX machine to test on so if someone beats me
to it all the better :)

[1] https://www.allegro.cc/forums/thread/615836

-sqweek

sqweek

unread,
Nov 11, 2015, 9:56:40 AM11/11/15
to Russ Cox, Marius Eriksen, plan9port-dev

Marius Eriksen

unread,
Nov 13, 2015, 11:21:07 AM11/13/15
to sqweek, Russ Cox, plan9port-dev
I haven’t seen windows failing to draw initially, though on occasion, I see blank windows after switching back and forth from fullscreen mode. OSX will often log API misuse to the console: open Console.app, and search for ‘acme’ (or whatever devdraw process). That might give a clue next time you observe it.

Thanks sqweek for the fix!

-m.

David Leimbach

unread,
Feb 19, 2021, 3:46:44 PM2/19/21
to plan9port-dev

I was just trying to figure out how to do a 2-1 chord with my trackpad on macOS and the idea of a force click + option sounds excellent.

Is there an alternative way to do a 2-1 chord if we don't take this patch (with a trackpad)?

Russ Cox

unread,
Feb 20, 2021, 11:11:59 AM2/20/21
to plan9port-dev, David Leimbach
I believe 2-1 chord is do a regular 2 selection (hold option and select)
and then press control before you let go of the rest.

That is, control-option-command across the bottom left of the
keyboard are buttons 1-2-3, whenever you need them.

I fear this may not be documented. 
It was first suggested in 2013 by Rubén Berenguel
but not implemented until 2018, in a9e66ff.
I've tested that it still works.

It also looks like in 9af9cec we added "four-finger tap"
as a 2-1 chord as well, although I honestly don't understand
the hand motions required to make that work. :-)
The 1-2-3 control-option-command makes more sense to me.

Best,
Russ


David Leimbach

unread,
Feb 20, 2021, 7:49:05 PM2/20/21
to Russ Cox, plan9port-dev
Ok, I must be doing this incorrectly.

I've got a scratch acme window with something like
(,x/.*\n/{
    x/[

David Leimbach

unread,
Feb 20, 2021, 7:53:40 PM2/20/21
to Russ Cox, plan9port-dev
Ok I hate gmail... it won't let me type characters like a normal human... trying again (and sorry for the noise... was quickly typing tab and spaces for whitespace matching, and it just sent the mail)

I've got a scratch window with some edit command sans the word "Edit".

I've selected it by left click and drag (or click and drag on a touchpad) and it is now a yellow highlight.

Now I move to the window I want to edit within and tried all of the following

4 finger tap the word "Edit" - it says (Edit: unknown command E)
select the word edit, dragging while holding option, then press ctrl and release - nothing, or sometimes "Edit: unknown command E".

Maybe I need to see this demonstrated.

Russ, was this in your acme video on youtube?

I should probably rewatch it, but I seem to remember there being an actual 3 button mouse.


David Leimbach

unread,
Feb 20, 2021, 7:56:23 PM2/20/21
to Russ Cox, plan9port-dev
Ah, nevermind, I got it working... It seems you have to make your you always re-select the command before a 4 finger tap will apply it as an argument.

Yeah those mechanics take a little getting used to, but I have to say Acme is still one of my favorite editors for macOS :-).

Edwood was looking pretty good too last time I tried it, but I've little reason to switch away from the classic!

Ethan Gardener

unread,
Feb 20, 2021, 10:21:29 PM2/20/21
to plan9p...@googlegroups.com
On Sun, Feb 21, 2021, at 12:56 AM, David Leimbach wrote:
Ah, nevermind, I got it working... It seems you have to make your you always re-select the command before a 4 finger tap will apply it as an argument.

Even with the actual 2-1 chord, it's all too common to lose the idea of latest selection to a single click somewhere (anywhere) else. This caught me out tons of times.

Reply all
Reply to author
Forward
0 new messages