From 6b39eba14c83124aa3b630afa6a4ca22ffab3e4b Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 6 Feb 2024 03:21:42 +0100 Subject: [PATCH 1/3] check if window scrolled #110 --- main.go | 10 ++++++++++ uicomponents.go | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index a9fd94b..6f7739f 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ var ( preferredApps map[string]interface{} exclusions []string hyprlandMonitors []monitor + beenScrolled bool ) var categoryNames = [...]string{ @@ -518,6 +519,15 @@ func main() { resultWindow.SetEvents(int(gdk.ALL_EVENTS_MASK)) resultWindow.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + vAdj := resultWindow.GetVAdjustment() + vAdj.Connect("value-changed", func() { + beenScrolled = true + }) + hAdj := resultWindow.GetVAdjustment() + hAdj.Connect("value-changed", func() { + beenScrolled = true + }) + resultWindow.Connect("button-release-event", func(_ *gtk.ScrolledWindow, event *gdk.Event) bool { btnEvent := gdk.EventButtonNewFromEvent(event) if btnEvent.Button() == 3 { diff --git a/uicomponents.go b/uicomponents.go index 6997570..ea79909 100644 --- a/uicomponents.go +++ b/uicomponents.go @@ -264,11 +264,18 @@ func flowBoxButton(entry desktopEntry) *gtk.Button { r := substring(desc, 0, 117) desc = fmt.Sprintf("%s…", string(r)) } + + button.Connect("button-press-event", func() { + beenScrolled = false + }) + button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool { btnEvent := gdk.EventButtonNewFromEvent(e) if btnEvent.Button() == 1 { - launch(exec, terminal) - return true + if !beenScrolled { + launch(exec, terminal) + return true + } } else if btnEvent.Button() == 3 { pinItem(ID) return true From ec3caa02d2a2ac36a654257cffb36a5c1e9cf084 Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 6 Feb 2024 03:33:12 +0100 Subject: [PATCH 2/3] add comments #110 --- main.go | 3 +++ uicomponents.go | 1 + 2 files changed, 4 insertions(+) diff --git a/main.go b/main.go index 6f7739f..68745b6 100644 --- a/main.go +++ b/main.go @@ -519,6 +519,9 @@ func main() { resultWindow.SetEvents(int(gdk.ALL_EVENTS_MASK)) resultWindow.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + // On touch screen we don't want the button-release-event to launch the app if the user just wanted to scroll the + // window. Let's forbid doing so if the content has been scrolled. We will reset the value on button-press-event. + // Resolves https://github.com/nwg-piotr/nwg-drawer/issues/110 vAdj := resultWindow.GetVAdjustment() vAdj.Connect("value-changed", func() { beenScrolled = true diff --git a/uicomponents.go b/uicomponents.go index ea79909..d5254ab 100644 --- a/uicomponents.go +++ b/uicomponents.go @@ -266,6 +266,7 @@ func flowBoxButton(entry desktopEntry) *gtk.Button { } button.Connect("button-press-event", func() { + // if not scrolled from now on, we will allow launching apps on button-release-event beenScrolled = false }) From ec0ce767d926a3f7a765bc5ddb70ee39c50e00da Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 6 Feb 2024 03:35:29 +0100 Subject: [PATCH 3/3] get proper adjustment --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 68745b6..d17255d 100644 --- a/main.go +++ b/main.go @@ -526,7 +526,7 @@ func main() { vAdj.Connect("value-changed", func() { beenScrolled = true }) - hAdj := resultWindow.GetVAdjustment() + hAdj := resultWindow.GetHAdjustment() hAdj.Connect("value-changed", func() { beenScrolled = true })