gotk3 / gotk3

Go bindings for GTK3
ISC License
2.11k stars 230 forks source link

Mouse wheel not work if mouse button is pressed [not bug] #370

Closed SilentGopherLnx closed 5 years ago

SilentGopherLnx commented 5 years ago

Mouse wheel not work if mouse button is keeping pressed. No reaction in event listener and in ScrolledWindow. Is this "gotk" bug or I should change something in code?

Small example code:

package main

import (
    "fmt"
    "os"
    "strconv"

    "github.com/gotk3/gotk3/gdk"
    "github.com/gotk3/gotk3/gtk"
)

func main() {

    gtk.Init(nil)
    win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
    win.Connect("destroy", func() {
        fmt.Println("bye")
        os.Exit(0)
    })
    win.SetDefaultSize(300, 200)
    win.SetTitle("scroll test")

    scroll_n := 0
    win.Connect("scroll-event", func(_ *gtk.Window, event *gdk.Event) {
        scroll_n++
        fmt.Println("scroll - " + strconv.Itoa(scroll_n))
    })

    big_content, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
    label0, _ := gtk.LabelNew("try mouse whell scroll with left mouse button pressed")
    big_content.Add(label0)
    for j := 0; j < 99; j++ {
        label, _ := gtk.LabelNew("text_" + strconv.Itoa(j+1))
        big_content.Add(label)
    }

    scroll, _ := gtk.ScrolledWindowNew(nil, nil)
    scroll.SetVExpand(true)
    scroll.SetHExpand(true)
    scroll.Add(big_content)

    win.Add(scroll)
    win.ShowAll()

    for {
        gtk.MainIteration()
    }

}
Bios-Marcel commented 5 years ago

I am unsure whether this is desired behaviour or not. Try writing the same application in C or Vala in order to test it out. Also, why are you doing this:

for {
    gtk.MainIteration()
}

Did anyone recommend you to do so?

SilentGopherLnx commented 5 years ago

is it not equivalent to the following: gtk.Main() ? My full code looks like this:

go start_async_loading(chan_var)
for {
    select {
    case loaded_data := <-chan_var:
        gtk_label_object.SetText(loaded_data)
    default:
        //CONTINUE!!
    }
    gtk.MainIteration()
}
SilentGopherLnx commented 5 years ago

ok. This solved my problem =) scroll.SetEvents(int(gdk.ALL_EVENTS_MASK))

Bios-Marcel commented 5 years ago

Have you managed doing this via trial and error? Or does the documentation recommend you to do so? Because this seems a bit odd to me. Maybe it doesn't even make sense to count the scrolling event while a mouse-button is down.

SilentGopherLnx commented 5 years ago

Yes, via trial and error. I am creating file manager (look at my repos). Such programs usually allow to select files by mouse. So I needed scroll to work.