Re: Motion events in a DrawingArea



You can just set up an anonymous signal handler like below:

$window->signal_connect(
        'realize' => sub {
            $window->set_events(
                [
                    'button-press-mask', 'button-motion-mask',
                    'button-release-mask'
                ]
         );
}

This will request the events only when you can be sure the window is realized.

oldtechaa


On Aug 16, 2017 8:12 AM, "Daniel Kasak" <d j kasak dk gmail com> wrote:
Hi all.

I'm trying to capture mouse events in a DrawingArea ( in Gtk3 ). I'm
adapting code at http://www.perlmonks.org/?node_id=583578 ... but when
I go:

$self->{drawing_area}->set_events(
    [ qw/   exposure-mask
            leave-notify-mask
            button-press-mask
            pointer-motion-mask
            pointer-motion-hint-mask
        /
    ]
);

 ... I get a warning:

Gtk-CRITICAL **: gtk_widget_set_events: assertion
'!_gtk_widget_get_realized (widget)' failed

I've tried putting this later on in the code when I guess the widget
*should* be realized, eg at the end of the render_graph() method which
I hook up thus:

$self->{drawing_area}->signal_connect( draw => sub {
$self->render_graph( @_ ) } );

 ... but it still gives the same error.

Next I try to connect to a signal handler anyway:

$self->{drawing_area}->signal_connect(
    'motion_notify_event'
  , sub { $self->handle_graph_mouse_move( @_ ) }
);

 ... but this handler never gets called.

I guess things have changed in Gtk3? I haven't been able to find an
updated demo, even in C. Any hints as to what I'm missing?

Dan
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]