~sircmpwn/aerc

Prevent the part-switcher from acting on events not meant for it v2 PROPOSED

Nicolai Dagestad: 3
 Prevent the part-switcher from acting on events not meant for it
 Pass mouse events to the undeliying terminal widget
 Correctly pass MouseEvents to the terminal widget when a message only has one part

 4 files changed, 20 insertions(+), 3 deletions(-)
I was going to explain why I did it in this way but I now see how strange the 
logic in the mouse event handling is...

I see I messed up a little bit in the content of the two other commits as well,
so I think I'll fix that and change the mouse event handling at the same 
time.
Ha, I see why it is done this way, the msgviewer widget is in fact not like you
drew it but like this

|-------------------------------|
|     y      msg viewer         |
||-----------------------------||
||    z      HeaderLayout      ||
||-----------------------------||
||  Content of message part    ||
||                             ||
||    x      part switcher     ||
||-----------------------------||
|-------------------------------|

So the list of part types and the message content are both part of the part 
switcher. The questions is then, would other people than me want a scroll in 
the message body to scroll the message instead of switching the message part 
like it does now.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/15106/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH v2 1/3] Prevent the part-switcher from acting on events not meant for it Export this patch

---
 widgets/msgviewer.go | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 6c69577..406185e 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -405,6 +405,7 @@ func (ps *PartSwitcher) MouseEvent(localX int, localY int, event tcell.Event) {
			y := ps.height - height
			if localY < y && ps.parts[ps.selected].term != nil {
				ps.parts[ps.selected].term.MouseEvent(localX, localY, event)
				return
			}
			if ps.parts[ps.selected].term != nil {
				ps.parts[ps.selected].term.Focus(false)
@@ -418,6 +419,7 @@ func (ps *PartSwitcher) MouseEvent(localX int, localY int, event tcell.Event) {
			y := ps.height - height
			if localY < y && ps.parts[ps.selected].term != nil {
				ps.parts[ps.selected].term.MouseEvent(localX, localY, event)
				return
			}
			if ps.parts[ps.selected].term != nil {
				ps.parts[ps.selected].term.Focus(false)
-- 
2.29.2
Hi,
Remind me, why are we not simply routing the mouse events based on the location?
I don't really like the fact that the mouse movement is dependent on what's on the
screen.

I think it'd be less surprising if what ever the underlying widget under the
mouse is actually gets "focus" so to speak.
Or is this a bad idea?

Know what I mean?

|-------------------------------|
|                               |
|     y      msg viewer         |
|                               |
|                               |
|-------------------------------|
|     x     part switcher       |
|-------------------------------|

If your mouse is where the x is I'd want mouse events to go to the part switcher.
If on y, to the msg viewer.

The other widget would never even see the mouse events and hence also doesn't
need to check if the mouse is out of bounds of itself.

Or am I misunderstanding what your code is doing?

Cheers,
Reto

[PATCH v2 2/3] Pass mouse events to the undeliying terminal widget Export this patch

---
v1 -> v2 Remove the non exported MouseMove function

 widgets/terminal.go | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/widgets/terminal.go b/widgets/terminal.go
index 77da71e..2e6f4a7 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -324,6 +324,21 @@ func (term *Terminal) MouseEvent(localX int, localY int, event tcell.Event) {
		if term.closed {
			return
		}
		button := event.Buttons()
		internal_value := int(button)
		switch button {
		case tcell.WheelUp:
			internal_value = 4
		case tcell.WheelDown:
			internal_value = 5
		case tcell.WheelRight:
			internal_value = 6
		case tcell.WheelLeft:
			internal_value = 7
		}
		term.vterm.MouseButton(internal_value, button == tcell.ButtonNone,
			convertMods(event.Modifiers()))
		term.flushTerminal()
	}
}

-- 
2.29.2

[PATCH v2 3/3] Correctly pass MouseEvents to the terminal widget when a message only has one part Export this patch

---
 widgets/msgviewer.go | 4 ++--
 widgets/terminal.go  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 406185e..ffc0161 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -403,7 +403,7 @@ func (ps *PartSwitcher) MouseEvent(localX int, localY int, event tcell.Event) {
		case tcell.WheelDown:
			height := len(ps.parts)
			y := ps.height - height
			if localY < y && ps.parts[ps.selected].term != nil {
			if ps.height == 0 || (localY < y && ps.parts[ps.selected].term != nil) {
				ps.parts[ps.selected].term.MouseEvent(localX, localY, event)
				return
			}
@@ -417,7 +417,7 @@ func (ps *PartSwitcher) MouseEvent(localX int, localY int, event tcell.Event) {
		case tcell.WheelUp:
			height := len(ps.parts)
			y := ps.height - height
			if localY < y && ps.parts[ps.selected].term != nil {
			if ps.height == 0 || (localY < y && ps.parts[ps.selected].term != nil) {
				ps.parts[ps.selected].term.MouseEvent(localX, localY, event)
				return
			}
diff --git a/widgets/terminal.go b/widgets/terminal.go
index 2e6f4a7..149cc74 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -9,7 +9,7 @@ import (
	"git.sr.ht/~sircmpwn/aerc/lib/ui"

	"github.com/creack/pty"
	"github.com/ddevault/go-libvterm"
	"git.sr.ht/~sircmpwn/go-libvterm"
	"github.com/gdamore/tcell"
)

-- 
2.29.2