Re: Gtk2::MenuItem on a StatusIcon disapears on mouse-up



Hi

I think your problem is due to the fact that when you call $menu->popup
you're passing a 0 for the last parameter (the activate time).  What you
need to do is pass $event->time.

The event object is passed to your signal handler so you may want to
change your code from:

$icon->signal_connect('popup-menu' => sub { show_icon_menu($icon); } );

to:

$icon->signal_connect('popup-menu' => sub { show_icon_menu(@_); } );

and

sub show_icon_menu {
    my($icon, $event) = @_;

...

    $menu->popup(undef, undef, sub { return
Gtk2::StatusIcon::position_menu($menu, 0, 0, $icon); }, [1,1], 0,
$event->time );

Sorry, I haven't tested that.

Cheers
Grant


On Sun, 2007-06-10 at 17:07 +0200, Tijmen Ruizendaal wrote:
Hello!

I have a StatusIcon for an application of me. If right click on the
icon, I want to show a menu. I use the signal 'popup-menu'.

The menu appears at mouse-down. and while holding the button, it
disappears at mouse-up as well. This is normal behaviour for a
statusicon.

However, if I do a mouse click without holding the button down, but
releasing it immidiately, the menu dissapears to. So the menu is
visible for like 100ms. then it's gone again. This is not what i
expected.

All the other items (power manager and network manager) in my
notification area behave correctly. I can right click, and the menu
shows up. I can hold down the button and the menu disappears at
mouse-up

I think it's a bug. But it might be my code as well.

Version information:
I run Ubuntu Gutsy Gibbon (development branch at this moment).
Notification Area 2.19.2
Gnome Panel 2.19.2
libgtk2-perl 1:1.140-1build1 from gutsy gibbon.


Below a small testcase which has the same code as in my project, and
the same behavior.

I hope someone can help me out, or confirm the bug.

Thanks,

Tijmen


Code:
---

#!/usr/bin/perl

use Gtk2 '-init';
use strict;

my $file = '/home/tijmen/Projects/Gtk2-BitlBee/release/gtk2-bitlbee-0.2.5/glade/BeeHive.png';

my $icon = Gtk2::StatusIcon->new();

$icon->set_from_file($file);
$icon->set_visible(1);
$icon->signal_connect('popup-menu' => sub { show_icon_menu($icon); } );
$icon->set_tooltip('Gtk2 BitlBee, Bzzzz...');
print "StatusIcon loaded\n";


sub show_icon_menu {
        my $menu = Gtk2::Menu->new();
        my $menuitem = Gtk2::MenuItem->new('Preferences');

        my $nicksitem = Gtk2::MenuItem->new('Nicks');
        $nicksitem->show();

        my $allnicks = new Gtk2::Menu->new();

        my @nicks = ('foo', 'bar', 'me', 'you');

        foreach my $nick (@nicks) {
                my $nickitem = Gtk2::MenuItem->new($nick);
                $nickitem->show();
                $allnicks->append($nickitem);
        }

        $nicksitem->set_submenu($allnicks);

        $menuitem->show();
        $menuitem->signal_connect('activate', sub { print "Click\n"; });
        $menu->append($menuitem);
        $menu->append($nicksitem);
        $menu->show_all();
        $menu->popup(undef, undef, sub { return
Gtk2::StatusIcon::position_menu($menu, 0, 0, $icon); }, [1,1], 0, 0 );

}

Gtk2->main;


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




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