commit 36cbd41

delthas  ·  2024-07-24 15:49:24 +0000 UTC
parent c37f59b
Open non-image links with unmodified mouse left clicks on foot
1 files changed,  +15, -1
M app.go
M app.go
+15, -1
 1@@ -12,8 +12,10 @@ import (
 2 	"mime"
 3 	"net"
 4 	"net/http"
 5+	"net/url"
 6 	"os"
 7 	"os/exec"
 8+	"path"
 9 	"path/filepath"
10 	"strings"
11 	"sync"
12@@ -929,7 +931,19 @@ func (app *App) fetchImage(link string) (image.Image, error) {
13 }
14 
15 func (app *App) handleLinkEvent(ev *events.EventClickLink) {
16-	if ev.Event.Modifiers == vaxis.ModCtrl {
17+	var open bool
18+	if ev.Mouse {
19+		open = true
20+		if ev.Event.Modifiers != vaxis.ModCtrl {
21+			if u, err := url.Parse(ev.Link); err == nil {
22+				switch strings.ToLower(path.Ext(u.Path)) {
23+				case ".jpg", ".jpeg", ".png", ".gif":
24+					open = false
25+				}
26+			}
27+		}
28+	}
29+	if open {
30 		if strings.HasPrefix(ev.Link, "-") {
31 			// Avoid injection of parameters.
32 			// Sadly xdg-open does not support "--"...