9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] drawterm/gui-cocoa/screen.m: mouse button emulation a la plan9port
@ 2020-12-21 15:05 boehm.igor
  0 siblings, 0 replies; 7+ messages in thread
From: boehm.igor @ 2020-12-21 15:05 UTC (permalink / raw)
  To: 9front

Dear all,

Inline is a patch that eases the use of drawterm on mac laptops that
lack mouse buttons.

For consistency reasons it behaves the same as on plan9port, namely
like this:

"For systems without a three button mouse, the keyboard modifier keys
can be used to modify the effect of the main mouse button.  On Mac
systems, the option key changes the main button to button 2, and the
Command key changes it to button 3.

Pressing the key after the button is held down adds the button to form
a chord, so that for example on Macs selecting text with the trackpad
button and then typing Option without letting go of the button will
cause a 1-2 chord, cutting the selection.

These changes were inspired by rsc's plan9port."

If you prefer to view this diff on GitHub here is a link:
https://github.com/1g0rb0hm/drawterm/commit/6cc968737b0ba5476516b698d8a539d5a2b26b62

If this is not the right place to propose drawterm patches or if
changes should be made please let me know.

Cheers,
Igor


diff -r 1f70be1f0305 gui-cocoa/screen.m
--- a/gui-cocoa/screen.m	Wed Nov 18 23:01:01 2020 +0100
+++ b/gui-cocoa/screen.m	Mon Dec 21 15:12:23 2020 +0100
@@ -364,43 +364,76 @@
 		kbdkey(m, 0);
 }
 
+- (void)sendmouse:(NSUInteger)b
+{
+	NSPoint p;
+	Point q;
+
+	p = [self.window mouseLocationOutsideOfEventStream];
+	q.x = p.x;
+	q.y = p.y;
+	if(!ptinrect(q, gscreen->clipr)) return;
+	absmousetrack(p.x, self.frame.size.height - p.y, b, ticks());
+}
+
 - (void)flagsChanged:(NSEvent*)event {
-	static NSEventModifierFlags y;
-	NSEventModifierFlags x;
+	static NSEventModifierFlags omod;
+	NSEventModifierFlags m;
+	NSUInteger b;
 
-	x = [event modifierFlags];
-	if((x & ~y & NSEventModifierFlagShift) != 0)
-		kbdkey(Kshift, 1);
-	if((x & ~y & NSEventModifierFlagControl) != 0)
-		kbdkey(Kctl, 1);
-	if((x & ~y & NSEventModifierFlagOption) != 0)
-		kbdkey(Kalt, 1);
-	if((x & ~y & NSEventModifierFlagCapsLock) != 0)
-		kbdkey(Kcaps, 1);
-	if((~x & y & NSEventModifierFlagShift) != 0)
-		kbdkey(Kshift, 0);
-	if((~x & y & NSEventModifierFlagControl) != 0)
-		kbdkey(Kctl, 0);
-	if((~x & y & NSEventModifierFlagOption) != 0)
-		kbdkey(Kalt, 0);
-	if((x & ~y & NSEventModifierFlagCapsLock) != 0)
-		kbdkey(Kcaps, 0);
-	y = x;
+	m = [event modifierFlags];
+	b = [NSEvent pressedMouseButtons];
+	b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
+	if(b){
+		if(m & ~omod & NSEventModifierFlagControl)
+			b |= 1;
+		if(m & ~omod & NSEventModifierFlagOption)
+			b |= 2;
+		if(m & ~omod & NSEventModifierFlagCommand)
+			b |= 4;
+		[self sendmouse:b];
+	}else{
+		if((m & ~omod & NSEventModifierFlagShift) != 0)
+			kbdkey(Kshift, 1);
+		if((m & ~omod & NSEventModifierFlagControl) != 0)
+			kbdkey(Kctl, 1);
+		if((m & ~omod & NSEventModifierFlagOption) != 0)
+			kbdkey(Kalt, 1);
+		if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
+			kbdkey(Kcaps, 1);
+		if((~m & omod & NSEventModifierFlagShift) != 0)
+			kbdkey(Kshift, 0);
+		if((~m & omod & NSEventModifierFlagControl) != 0)
+			kbdkey(Kctl, 0);
+		if((~m & omod & NSEventModifierFlagOption) != 0)
+			kbdkey(Kalt, 0);
+		if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
+			kbdkey(Kcaps, 0);
+	}
+	omod = m;
 }
 
 - (void)mouseevent:(NSEvent*)event
 {
-	NSPoint p;
-	Point q;
-	NSUInteger u;
+	NSUInteger b;
+	NSEventModifierFlags m;
 
-	p = [self.window mouseLocationOutsideOfEventStream];
-	u = [NSEvent pressedMouseButtons];
-	q.x = p.x;
-	q.y = p.y;
-	if(!ptinrect(q, gscreen->clipr)) return;
-	u = u & ~6 | u << 1 & 4 | u >> 1 & 2;
-	absmousetrack(p.x, self.frame.size.height - p.y, u, ticks());
+	b = [NSEvent pressedMouseButtons];
+	b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
+	if(b==1){
+		m = [event modifierFlags];
+		if(m & NSEventModifierFlagOption)
+			b=2;
+		else if(m & NSEventModifierFlagCommand)
+			b=4;
+		else if(m & NSEventModifierFlagControl)
+			b=8;
+	}else if(b==4){
+		m = [event modifierFlags];
+		if(m & NSEventModifierFlagCommand)
+			b=8;
+	}
+	[self sendmouse:b];
 }
 
 - (void) mouseDown:(NSEvent*)event { [self mouseevent:event]; }




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] drawterm/gui-cocoa/screen.m: mouse button emulation a la plan9port
  2021-06-17  7:35   ` igor
@ 2021-06-17 13:01     ` Eric Lynema
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Lynema @ 2021-06-17 13:01 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 6925 bytes --]

Would this also work on the windows port? I would love to have the option
to not cary around a mouse if I didn't need to.

On Thu, Jun 17, 2021, 3:50 AM <igor@9lab.org> wrote:

> Quoth unobe@cpan.org:
> > Did this patch request get lost? Or was there an issue with it?
>
> I have never followed up and pushed for it. Maybe now is an opportune
> moment to resume that effort…
>
> There is actually one much more grave issue in the Darwin port
> of Drawterm that happens when the cursor is updated frequently.
>
> Try navigating to a website with netsurf and hover over links
> so the cursor changes frequently. Very likely you run into
> a SEGFAULT. This happens on OSX Catalina and BigSur.
>
> Here is the fix for it:
>
> mac: fix SEGFAULT during cursor updates
> •
> https://github.com/1g0rb0hm/drawterm/commit/01a3a73ebebfd765918f6104e58154e7a7f56cff
>
> Will resurrect the patches and resubmit them, the one with the
> simulated buttons as well as the fix for the SEGFAULT.
>
> BTW.  if you are interested in having Audio via Drawterm on OSX you
> might be interested in this one (thanks to Tony Mendoza
> https://github.com/tmendoza/drawterm-macos-audio):
>
> •
> https://github.com/1g0rb0hm/drawterm/commit/9dbda7617c22f4efe4bb58224bd5d99ce36da8e7
>
> Cheers,
> Igor
>
> >
> > Quoth boehm.igor@gmail.com:
> > > Dear all,
> > >
> > > Inline is a patch that eases the use of drawterm on mac laptops that
> > > lack mouse buttons.
> > >
> > > For consistency reasons it behaves the same as on plan9port, namely
> > > like this:
> > >
> > > "For systems without a three button mouse, the keyboard modifier keys
> > > can be used to modify the effect of the main mouse button.  On Mac
> > > systems, the option key changes the main button to button 2, and the
> > > Command key changes it to button 3.
> > >
> > > Pressing the key after the button is held down adds the button to form
> > > a chord, so that for example on Macs selecting text with the trackpad
> > > button and then typing Option without letting go of the button will
> > > cause a 1-2 chord, cutting the selection.
> > >
> > > These changes were inspired by rsc's plan9port."
> > >
> > > If you prefer to view this diff on GitHub here is a link:
> > >
> https://github.com/1g0rb0hm/drawterm/commit/6cc968737b0ba5476516b698d8a539d5a2b26b62
> > >
> > > If this is not the right place to propose drawterm patches or if
> > > changes should be made please let me know.
> > >
> > > Cheers,
> > > Igor
> > >
> > > diff -r 1f70be1f0305 gui-cocoa/screen.m
> > > --- a/gui-cocoa/screen.m    Wed Nov 18 23:01:01 2020 +0100
> > > +++ b/gui-cocoa/screen.m    Mon Dec 21 15:12:23 2020 +0100
> > > @@ -364,43 +364,76 @@
> > >             kbdkey(m, 0);
> > >  }
> > >
> > > +- (void)sendmouse:(NSUInteger)b
> > > +{
> > > +   NSPoint p;
> > > +   Point q;
> > > +
> > > +   p = [self.window mouseLocationOutsideOfEventStream];
> > > +   q.x = p.x;
> > > +   q.y = p.y;
> > > +   if(!ptinrect(q, gscreen->clipr)) return;
> > > +   absmousetrack(p.x, self.frame.size.height - p.y, b, ticks());
> > > +}
> > > +
> > >  - (void)flagsChanged:(NSEvent*)event {
> > > -   static NSEventModifierFlags y;
> > > -   NSEventModifierFlags x;
> > > +   static NSEventModifierFlags omod;
> > > +   NSEventModifierFlags m;
> > > +   NSUInteger b;
> > >
> > > -   x = [event modifierFlags];
> > > -   if((x & ~y & NSEventModifierFlagShift) != 0)
> > > -           kbdkey(Kshift, 1);
> > > -   if((x & ~y & NSEventModifierFlagControl) != 0)
> > > -           kbdkey(Kctl, 1);
> > > -   if((x & ~y & NSEventModifierFlagOption) != 0)
> > > -           kbdkey(Kalt, 1);
> > > -   if((x & ~y & NSEventModifierFlagCapsLock) != 0)
> > > -           kbdkey(Kcaps, 1);
> > > -   if((~x & y & NSEventModifierFlagShift) != 0)
> > > -           kbdkey(Kshift, 0);
> > > -   if((~x & y & NSEventModifierFlagControl) != 0)
> > > -           kbdkey(Kctl, 0);
> > > -   if((~x & y & NSEventModifierFlagOption) != 0)
> > > -           kbdkey(Kalt, 0);
> > > -   if((x & ~y & NSEventModifierFlagCapsLock) != 0)
> > > -           kbdkey(Kcaps, 0);
> > > -   y = x;
> > > +   m = [event modifierFlags];
> > > +   b = [NSEvent pressedMouseButtons];
> > > +   b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
> > > +   if(b){
> > > +           if(m & ~omod & NSEventModifierFlagControl)
> > > +                   b |= 1;
> > > +           if(m & ~omod & NSEventModifierFlagOption)
> > > +                   b |= 2;
> > > +           if(m & ~omod & NSEventModifierFlagCommand)
> > > +                   b |= 4;
> > > +           [self sendmouse:b];
> > > +   }else{
> > > +           if((m & ~omod & NSEventModifierFlagShift) != 0)
> > > +                   kbdkey(Kshift, 1);
> > > +           if((m & ~omod & NSEventModifierFlagControl) != 0)
> > > +                   kbdkey(Kctl, 1);
> > > +           if((m & ~omod & NSEventModifierFlagOption) != 0)
> > > +                   kbdkey(Kalt, 1);
> > > +           if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
> > > +                   kbdkey(Kcaps, 1);
> > > +           if((~m & omod & NSEventModifierFlagShift) != 0)
> > > +                   kbdkey(Kshift, 0);
> > > +           if((~m & omod & NSEventModifierFlagControl) != 0)
> > > +                   kbdkey(Kctl, 0);
> > > +           if((~m & omod & NSEventModifierFlagOption) != 0)
> > > +                   kbdkey(Kalt, 0);
> > > +           if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
> > > +                   kbdkey(Kcaps, 0);
> > > +   }
> > > +   omod = m;
> > >  }
> > >
> > >  - (void)mouseevent:(NSEvent*)event
> > >  {
> > > -   NSPoint p;
> > > -   Point q;
> > > -   NSUInteger u;
> > > +   NSUInteger b;
> > > +   NSEventModifierFlags m;
> > >
> > > -   p = [self.window mouseLocationOutsideOfEventStream];
> > > -   u = [NSEvent pressedMouseButtons];
> > > -   q.x = p.x;
> > > -   q.y = p.y;
> > > -   if(!ptinrect(q, gscreen->clipr)) return;
> > > -   u = u & ~6 | u << 1 & 4 | u >> 1 & 2;
> > > -   absmousetrack(p.x, self.frame.size.height - p.y, u, ticks());
> > > +   b = [NSEvent pressedMouseButtons];
> > > +   b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
> > > +   if(b==1){
> > > +           m = [event modifierFlags];
> > > +           if(m & NSEventModifierFlagOption)
> > > +                   b=2;
> > > +           else if(m & NSEventModifierFlagCommand)
> > > +                   b=4;
> > > +           else if(m & NSEventModifierFlagControl)
> > > +                   b=8;
> > > +   }else if(b==4){
> > > +           m = [event modifierFlags];
> > > +           if(m & NSEventModifierFlagCommand)
> > > +                   b=8;
> > > +   }
> > > +   [self sendmouse:b];
> > >  }
> > >
> > >  - (void) mouseDown:(NSEvent*)event { [self mouseevent:event]; }
> > >
> > >
> > >
> >
>
>

[-- Attachment #2: Type: text/html, Size: 9799 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] drawterm/gui-cocoa/screen.m: mouse button emulation a la plan9port
  2021-06-17  7:40   ` cinap_lenrek
@ 2021-06-17  7:50     ` unobe
  0 siblings, 0 replies; 7+ messages in thread
From: unobe @ 2021-06-17  7:50 UTC (permalink / raw)
  To: 9front

Quoth cinap_lenrek@felloff.net:
> never saw that one... mailinglist has eaten it?
> 
> looks good to me.
> 
> --
> cinap

It was from back in Dec.  2020, so it was from awhile ago (clearing
out some old e-mails that had piqued my interest).  I think that was
around the same time that there was testing with the mailing list.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] drawterm/gui-cocoa/screen.m: mouse button emulation a la plan9port
  2021-06-17  6:21 ` unobe
  2021-06-17  7:35   ` igor
@ 2021-06-17  7:40   ` cinap_lenrek
  2021-06-17  7:50     ` unobe
  1 sibling, 1 reply; 7+ messages in thread
From: cinap_lenrek @ 2021-06-17  7:40 UTC (permalink / raw)
  To: 9front

never saw that one... mailinglist has eaten it?

looks good to me.

--
cinap

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] drawterm/gui-cocoa/screen.m: mouse button emulation a la plan9port
  2021-06-17  6:21 ` unobe
@ 2021-06-17  7:35   ` igor
  2021-06-17 13:01     ` Eric Lynema
  2021-06-17  7:40   ` cinap_lenrek
  1 sibling, 1 reply; 7+ messages in thread
From: igor @ 2021-06-17  7:35 UTC (permalink / raw)
  To: 9front; +Cc: igor

Quoth unobe@cpan.org:
> Did this patch request get lost? Or was there an issue with it?

I have never followed up and pushed for it. Maybe now is an opportune
moment to resume that effort…

There is actually one much more grave issue in the Darwin port
of Drawterm that happens when the cursor is updated frequently.

Try navigating to a website with netsurf and hover over links
so the cursor changes frequently. Very likely you run into
a SEGFAULT. This happens on OSX Catalina and BigSur.

Here is the fix for it:

mac: fix SEGFAULT during cursor updates
• https://github.com/1g0rb0hm/drawterm/commit/01a3a73ebebfd765918f6104e58154e7a7f56cff

Will resurrect the patches and resubmit them, the one with the
simulated buttons as well as the fix for the SEGFAULT.

BTW.  if you are interested in having Audio via Drawterm on OSX you
might be interested in this one (thanks to Tony Mendoza
https://github.com/tmendoza/drawterm-macos-audio):https://github.com/1g0rb0hm/drawterm/commit/9dbda7617c22f4efe4bb58224bd5d99ce36da8e7

Cheers,
Igor

> 
> Quoth boehm.igor@gmail.com:
> > Dear all,
> > 
> > Inline is a patch that eases the use of drawterm on mac laptops that
> > lack mouse buttons.
> > 
> > For consistency reasons it behaves the same as on plan9port, namely
> > like this:
> > 
> > "For systems without a three button mouse, the keyboard modifier keys
> > can be used to modify the effect of the main mouse button.  On Mac
> > systems, the option key changes the main button to button 2, and the
> > Command key changes it to button 3.
> > 
> > Pressing the key after the button is held down adds the button to form
> > a chord, so that for example on Macs selecting text with the trackpad
> > button and then typing Option without letting go of the button will
> > cause a 1-2 chord, cutting the selection.
> > 
> > These changes were inspired by rsc's plan9port."
> > 
> > If you prefer to view this diff on GitHub here is a link:
> > https://github.com/1g0rb0hm/drawterm/commit/6cc968737b0ba5476516b698d8a539d5a2b26b62
> > 
> > If this is not the right place to propose drawterm patches or if
> > changes should be made please let me know.
> > 
> > Cheers,
> > Igor
> > 
> > diff -r 1f70be1f0305 gui-cocoa/screen.m
> > --- a/gui-cocoa/screen.m	Wed Nov 18 23:01:01 2020 +0100
> > +++ b/gui-cocoa/screen.m	Mon Dec 21 15:12:23 2020 +0100
> > @@ -364,43 +364,76 @@
> >  		kbdkey(m, 0);
> >  }
> >  
> > +- (void)sendmouse:(NSUInteger)b
> > +{
> > +	NSPoint p;
> > +	Point q;
> > +
> > +	p = [self.window mouseLocationOutsideOfEventStream];
> > +	q.x = p.x;
> > +	q.y = p.y;
> > +	if(!ptinrect(q, gscreen->clipr)) return;
> > +	absmousetrack(p.x, self.frame.size.height - p.y, b, ticks());
> > +}
> > +
> >  - (void)flagsChanged:(NSEvent*)event {
> > -	static NSEventModifierFlags y;
> > -	NSEventModifierFlags x;
> > +	static NSEventModifierFlags omod;
> > +	NSEventModifierFlags m;
> > +	NSUInteger b;
> >  
> > -	x = [event modifierFlags];
> > -	if((x & ~y & NSEventModifierFlagShift) != 0)
> > -		kbdkey(Kshift, 1);
> > -	if((x & ~y & NSEventModifierFlagControl) != 0)
> > -		kbdkey(Kctl, 1);
> > -	if((x & ~y & NSEventModifierFlagOption) != 0)
> > -		kbdkey(Kalt, 1);
> > -	if((x & ~y & NSEventModifierFlagCapsLock) != 0)
> > -		kbdkey(Kcaps, 1);
> > -	if((~x & y & NSEventModifierFlagShift) != 0)
> > -		kbdkey(Kshift, 0);
> > -	if((~x & y & NSEventModifierFlagControl) != 0)
> > -		kbdkey(Kctl, 0);
> > -	if((~x & y & NSEventModifierFlagOption) != 0)
> > -		kbdkey(Kalt, 0);
> > -	if((x & ~y & NSEventModifierFlagCapsLock) != 0)
> > -		kbdkey(Kcaps, 0);
> > -	y = x;
> > +	m = [event modifierFlags];
> > +	b = [NSEvent pressedMouseButtons];
> > +	b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
> > +	if(b){
> > +		if(m & ~omod & NSEventModifierFlagControl)
> > +			b |= 1;
> > +		if(m & ~omod & NSEventModifierFlagOption)
> > +			b |= 2;
> > +		if(m & ~omod & NSEventModifierFlagCommand)
> > +			b |= 4;
> > +		[self sendmouse:b];
> > +	}else{
> > +		if((m & ~omod & NSEventModifierFlagShift) != 0)
> > +			kbdkey(Kshift, 1);
> > +		if((m & ~omod & NSEventModifierFlagControl) != 0)
> > +			kbdkey(Kctl, 1);
> > +		if((m & ~omod & NSEventModifierFlagOption) != 0)
> > +			kbdkey(Kalt, 1);
> > +		if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
> > +			kbdkey(Kcaps, 1);
> > +		if((~m & omod & NSEventModifierFlagShift) != 0)
> > +			kbdkey(Kshift, 0);
> > +		if((~m & omod & NSEventModifierFlagControl) != 0)
> > +			kbdkey(Kctl, 0);
> > +		if((~m & omod & NSEventModifierFlagOption) != 0)
> > +			kbdkey(Kalt, 0);
> > +		if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
> > +			kbdkey(Kcaps, 0);
> > +	}
> > +	omod = m;
> >  }
> >  
> >  - (void)mouseevent:(NSEvent*)event
> >  {
> > -	NSPoint p;
> > -	Point q;
> > -	NSUInteger u;
> > +	NSUInteger b;
> > +	NSEventModifierFlags m;
> >  
> > -	p = [self.window mouseLocationOutsideOfEventStream];
> > -	u = [NSEvent pressedMouseButtons];
> > -	q.x = p.x;
> > -	q.y = p.y;
> > -	if(!ptinrect(q, gscreen->clipr)) return;
> > -	u = u & ~6 | u << 1 & 4 | u >> 1 & 2;
> > -	absmousetrack(p.x, self.frame.size.height - p.y, u, ticks());
> > +	b = [NSEvent pressedMouseButtons];
> > +	b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
> > +	if(b==1){
> > +		m = [event modifierFlags];
> > +		if(m & NSEventModifierFlagOption)
> > +			b=2;
> > +		else if(m & NSEventModifierFlagCommand)
> > +			b=4;
> > +		else if(m & NSEventModifierFlagControl)
> > +			b=8;
> > +	}else if(b==4){
> > +		m = [event modifierFlags];
> > +		if(m & NSEventModifierFlagCommand)
> > +			b=8;
> > +	}
> > +	[self sendmouse:b];
> >  }
> >  
> >  - (void) mouseDown:(NSEvent*)event { [self mouseevent:event]; }
> > 
> > 
> > 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] drawterm/gui-cocoa/screen.m: mouse button emulation a la plan9port
  2020-12-21 14:24 boehm.igor
@ 2021-06-17  6:21 ` unobe
  2021-06-17  7:35   ` igor
  2021-06-17  7:40   ` cinap_lenrek
  0 siblings, 2 replies; 7+ messages in thread
From: unobe @ 2021-06-17  6:21 UTC (permalink / raw)
  To: 9front

Did this patch request get lost? Or was there an issue with it?

Quoth boehm.igor@gmail.com:
> Dear all,
> 
> Inline is a patch that eases the use of drawterm on mac laptops that
> lack mouse buttons.
> 
> For consistency reasons it behaves the same as on plan9port, namely
> like this:
> 
> "For systems without a three button mouse, the keyboard modifier keys
> can be used to modify the effect of the main mouse button.  On Mac
> systems, the option key changes the main button to button 2, and the
> Command key changes it to button 3.
> 
> Pressing the key after the button is held down adds the button to form
> a chord, so that for example on Macs selecting text with the trackpad
> button and then typing Option without letting go of the button will
> cause a 1-2 chord, cutting the selection.
> 
> These changes were inspired by rsc's plan9port."
> 
> If you prefer to view this diff on GitHub here is a link:
> https://github.com/1g0rb0hm/drawterm/commit/6cc968737b0ba5476516b698d8a539d5a2b26b62
> 
> If this is not the right place to propose drawterm patches or if
> changes should be made please let me know.
> 
> Cheers,
> Igor
> 
> diff -r 1f70be1f0305 gui-cocoa/screen.m
> --- a/gui-cocoa/screen.m	Wed Nov 18 23:01:01 2020 +0100
> +++ b/gui-cocoa/screen.m	Mon Dec 21 15:12:23 2020 +0100
> @@ -364,43 +364,76 @@
>  		kbdkey(m, 0);
>  }
>  
> +- (void)sendmouse:(NSUInteger)b
> +{
> +	NSPoint p;
> +	Point q;
> +
> +	p = [self.window mouseLocationOutsideOfEventStream];
> +	q.x = p.x;
> +	q.y = p.y;
> +	if(!ptinrect(q, gscreen->clipr)) return;
> +	absmousetrack(p.x, self.frame.size.height - p.y, b, ticks());
> +}
> +
>  - (void)flagsChanged:(NSEvent*)event {
> -	static NSEventModifierFlags y;
> -	NSEventModifierFlags x;
> +	static NSEventModifierFlags omod;
> +	NSEventModifierFlags m;
> +	NSUInteger b;
>  
> -	x = [event modifierFlags];
> -	if((x & ~y & NSEventModifierFlagShift) != 0)
> -		kbdkey(Kshift, 1);
> -	if((x & ~y & NSEventModifierFlagControl) != 0)
> -		kbdkey(Kctl, 1);
> -	if((x & ~y & NSEventModifierFlagOption) != 0)
> -		kbdkey(Kalt, 1);
> -	if((x & ~y & NSEventModifierFlagCapsLock) != 0)
> -		kbdkey(Kcaps, 1);
> -	if((~x & y & NSEventModifierFlagShift) != 0)
> -		kbdkey(Kshift, 0);
> -	if((~x & y & NSEventModifierFlagControl) != 0)
> -		kbdkey(Kctl, 0);
> -	if((~x & y & NSEventModifierFlagOption) != 0)
> -		kbdkey(Kalt, 0);
> -	if((x & ~y & NSEventModifierFlagCapsLock) != 0)
> -		kbdkey(Kcaps, 0);
> -	y = x;
> +	m = [event modifierFlags];
> +	b = [NSEvent pressedMouseButtons];
> +	b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
> +	if(b){
> +		if(m & ~omod & NSEventModifierFlagControl)
> +			b |= 1;
> +		if(m & ~omod & NSEventModifierFlagOption)
> +			b |= 2;
> +		if(m & ~omod & NSEventModifierFlagCommand)
> +			b |= 4;
> +		[self sendmouse:b];
> +	}else{
> +		if((m & ~omod & NSEventModifierFlagShift) != 0)
> +			kbdkey(Kshift, 1);
> +		if((m & ~omod & NSEventModifierFlagControl) != 0)
> +			kbdkey(Kctl, 1);
> +		if((m & ~omod & NSEventModifierFlagOption) != 0)
> +			kbdkey(Kalt, 1);
> +		if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
> +			kbdkey(Kcaps, 1);
> +		if((~m & omod & NSEventModifierFlagShift) != 0)
> +			kbdkey(Kshift, 0);
> +		if((~m & omod & NSEventModifierFlagControl) != 0)
> +			kbdkey(Kctl, 0);
> +		if((~m & omod & NSEventModifierFlagOption) != 0)
> +			kbdkey(Kalt, 0);
> +		if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
> +			kbdkey(Kcaps, 0);
> +	}
> +	omod = m;
>  }
>  
>  - (void)mouseevent:(NSEvent*)event
>  {
> -	NSPoint p;
> -	Point q;
> -	NSUInteger u;
> +	NSUInteger b;
> +	NSEventModifierFlags m;
>  
> -	p = [self.window mouseLocationOutsideOfEventStream];
> -	u = [NSEvent pressedMouseButtons];
> -	q.x = p.x;
> -	q.y = p.y;
> -	if(!ptinrect(q, gscreen->clipr)) return;
> -	u = u & ~6 | u << 1 & 4 | u >> 1 & 2;
> -	absmousetrack(p.x, self.frame.size.height - p.y, u, ticks());
> +	b = [NSEvent pressedMouseButtons];
> +	b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
> +	if(b==1){
> +		m = [event modifierFlags];
> +		if(m & NSEventModifierFlagOption)
> +			b=2;
> +		else if(m & NSEventModifierFlagCommand)
> +			b=4;
> +		else if(m & NSEventModifierFlagControl)
> +			b=8;
> +	}else if(b==4){
> +		m = [event modifierFlags];
> +		if(m & NSEventModifierFlagCommand)
> +			b=8;
> +	}
> +	[self sendmouse:b];
>  }
>  
>  - (void) mouseDown:(NSEvent*)event { [self mouseevent:event]; }
> 
> 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [9front] drawterm/gui-cocoa/screen.m: mouse button emulation a la plan9port
@ 2020-12-21 14:24 boehm.igor
  2021-06-17  6:21 ` unobe
  0 siblings, 1 reply; 7+ messages in thread
From: boehm.igor @ 2020-12-21 14:24 UTC (permalink / raw)
  To: 9front, Igor, Boehm, boehm.igor

Dear all,

Inline is a patch that eases the use of drawterm on mac laptops that
lack mouse buttons.

For consistency reasons it behaves the same as on plan9port, namely
like this:

"For systems without a three button mouse, the keyboard modifier keys
can be used to modify the effect of the main mouse button.  On Mac
systems, the option key changes the main button to button 2, and the
Command key changes it to button 3.

Pressing the key after the button is held down adds the button to form
a chord, so that for example on Macs selecting text with the trackpad
button and then typing Option without letting go of the button will
cause a 1-2 chord, cutting the selection.

These changes were inspired by rsc's plan9port."

If you prefer to view this diff on GitHub here is a link:
https://github.com/1g0rb0hm/drawterm/commit/6cc968737b0ba5476516b698d8a539d5a2b26b62

If this is not the right place to propose drawterm patches or if
changes should be made please let me know.

Cheers,
Igor

diff -r 1f70be1f0305 gui-cocoa/screen.m
--- a/gui-cocoa/screen.m	Wed Nov 18 23:01:01 2020 +0100
+++ b/gui-cocoa/screen.m	Mon Dec 21 15:12:23 2020 +0100
@@ -364,43 +364,76 @@
 		kbdkey(m, 0);
 }
 
+- (void)sendmouse:(NSUInteger)b
+{
+	NSPoint p;
+	Point q;
+
+	p = [self.window mouseLocationOutsideOfEventStream];
+	q.x = p.x;
+	q.y = p.y;
+	if(!ptinrect(q, gscreen->clipr)) return;
+	absmousetrack(p.x, self.frame.size.height - p.y, b, ticks());
+}
+
 - (void)flagsChanged:(NSEvent*)event {
-	static NSEventModifierFlags y;
-	NSEventModifierFlags x;
+	static NSEventModifierFlags omod;
+	NSEventModifierFlags m;
+	NSUInteger b;
 
-	x = [event modifierFlags];
-	if((x & ~y & NSEventModifierFlagShift) != 0)
-		kbdkey(Kshift, 1);
-	if((x & ~y & NSEventModifierFlagControl) != 0)
-		kbdkey(Kctl, 1);
-	if((x & ~y & NSEventModifierFlagOption) != 0)
-		kbdkey(Kalt, 1);
-	if((x & ~y & NSEventModifierFlagCapsLock) != 0)
-		kbdkey(Kcaps, 1);
-	if((~x & y & NSEventModifierFlagShift) != 0)
-		kbdkey(Kshift, 0);
-	if((~x & y & NSEventModifierFlagControl) != 0)
-		kbdkey(Kctl, 0);
-	if((~x & y & NSEventModifierFlagOption) != 0)
-		kbdkey(Kalt, 0);
-	if((x & ~y & NSEventModifierFlagCapsLock) != 0)
-		kbdkey(Kcaps, 0);
-	y = x;
+	m = [event modifierFlags];
+	b = [NSEvent pressedMouseButtons];
+	b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
+	if(b){
+		if(m & ~omod & NSEventModifierFlagControl)
+			b |= 1;
+		if(m & ~omod & NSEventModifierFlagOption)
+			b |= 2;
+		if(m & ~omod & NSEventModifierFlagCommand)
+			b |= 4;
+		[self sendmouse:b];
+	}else{
+		if((m & ~omod & NSEventModifierFlagShift) != 0)
+			kbdkey(Kshift, 1);
+		if((m & ~omod & NSEventModifierFlagControl) != 0)
+			kbdkey(Kctl, 1);
+		if((m & ~omod & NSEventModifierFlagOption) != 0)
+			kbdkey(Kalt, 1);
+		if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
+			kbdkey(Kcaps, 1);
+		if((~m & omod & NSEventModifierFlagShift) != 0)
+			kbdkey(Kshift, 0);
+		if((~m & omod & NSEventModifierFlagControl) != 0)
+			kbdkey(Kctl, 0);
+		if((~m & omod & NSEventModifierFlagOption) != 0)
+			kbdkey(Kalt, 0);
+		if((m & ~omod & NSEventModifierFlagCapsLock) != 0)
+			kbdkey(Kcaps, 0);
+	}
+	omod = m;
 }
 
 - (void)mouseevent:(NSEvent*)event
 {
-	NSPoint p;
-	Point q;
-	NSUInteger u;
+	NSUInteger b;
+	NSEventModifierFlags m;
 
-	p = [self.window mouseLocationOutsideOfEventStream];
-	u = [NSEvent pressedMouseButtons];
-	q.x = p.x;
-	q.y = p.y;
-	if(!ptinrect(q, gscreen->clipr)) return;
-	u = u & ~6 | u << 1 & 4 | u >> 1 & 2;
-	absmousetrack(p.x, self.frame.size.height - p.y, u, ticks());
+	b = [NSEvent pressedMouseButtons];
+	b = b & ~6 | b << 1 & 4 | b >> 1 & 2;
+	if(b==1){
+		m = [event modifierFlags];
+		if(m & NSEventModifierFlagOption)
+			b=2;
+		else if(m & NSEventModifierFlagCommand)
+			b=4;
+		else if(m & NSEventModifierFlagControl)
+			b=8;
+	}else if(b==4){
+		m = [event modifierFlags];
+		if(m & NSEventModifierFlagCommand)
+			b=8;
+	}
+	[self sendmouse:b];
 }
 
 - (void) mouseDown:(NSEvent*)event { [self mouseevent:event]; }




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-06-17 14:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 15:05 [9front] drawterm/gui-cocoa/screen.m: mouse button emulation a la plan9port boehm.igor
  -- strict thread matches above, loose matches on Subject: below --
2020-12-21 14:24 boehm.igor
2021-06-17  6:21 ` unobe
2021-06-17  7:35   ` igor
2021-06-17 13:01     ` Eric Lynema
2021-06-17  7:40   ` cinap_lenrek
2021-06-17  7:50     ` unobe

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).