Gtk3 context menu



Hi all. Some code I had that used to work ( I think anyway ) in Gtk2 no longer works:

---

in the constructor, I do:

$treeview->signal_connect( button_press_event => sub { $self->on_tree_click( @_ ) } );

then ...

sub on_tree_click {
   
    my ( $self, $widget, $event ) = @_;
   
    my $type    = $event->type;
    my $button  = $event->button;
   
    print "caught: type [$type] button [$button]\nobj: " . Dumper( $button ) . "\n";
   
    if ( $type eq '2button-press' ) {
       
        $self->handle_double_click( $widget, $event );
       
    } elsif ( $button == 3 ) {
       
        $self->build_context_menu( $widget, $event );
       
    }
   
}

sub build_context_menu {
   
    my ( $self, $widget, $event ) = @_;
   
    my $menu = Gtk3::Menu->new;
   
    foreach my $context_action ( 'refresh', 'edit' ) {
        my $item = Gtk3::MenuItem->new( $context_action );
        $menu->append( $item );
        $item->show;
        $item->signal_connect( activate => sub { $self->$context_action ; } );
    }
   
    $menu->popup( undef, undef, undef, undef, $event->button, $event->time );
   
}

---

Everything in on_tree_click appears to be working, and it's calling handle_double_click() and build_context_menu() at the appropriate times. However building the context menu is not working. If right-click once, nothing happens. If I double-right-click, then I get a grey box appearing where the menu should be, but then handle_double_click() is called, and when it's done, the grey box disappears. Lastly, my $button is receiving a HASH instead of a number when I double-click:

caught: type [button-press] button [3]
obj: $VAR1 = 3;

caught: type [button-press] button [3]
obj: $VAR1 = 3;

caught: type [2button-press] button [HASH(0x480e228)]
obj: $VAR1 = {
          'x_root' => '86.7047119140625',
          'y_root' => '199.390365600586',
          'window' => bless( {}, 'Glib::Object::_Unregistered::GdkX11Window' ),
          'time' => 95324125,
          'x' => '80.7047119140625',
          'send_event' => 0,
          'device' => bless( {}, 'Glib::Object::_Unregistered::GdkX11DeviceXI2' ),
          'axes' => '3.73453945125965e-316',
          'state' => bless( do{\(my $o = 0)}, 'Gtk3::Gdk::ModifierType' ),
          'y' => '13.3903656005859',
          'button' => 3,
          'type' => '2button-press'
        };

What's going on? Why is $button sometimes a hash? And why doesn't my menu render properly?

Dan


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