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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Tijmen Ruizendaal
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
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

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

Grant McLean
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
> [hidden email]
> http://mail.gnome.org/mailman/listinfo/gtk-perl-list

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

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

Grant McLean
On Mon, 2007-06-11 at 14:59 +1200, Grant McLean wrote:
> 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.

Perhaps it might be a good idea to amend the example accordingly:

--- Gtk2/examples/cellrenderer_popup.pl 10 Jul 2004 02:52:54 -0000
1.9
+++ Gtk2/examples/cellrenderer_popup.pl 11 Jun 2007 03:08:48 -0000
@@ -209,7 +209,7 @@
        $menu->set_active ($cell->{index});
        $menu->popup (undef, undef,
                      \&menu_pos_func, [$widget, $cell_area],
-                     $event ? $event->button : 0, 0);
+                     $event ? $event->button : 0, $event->time);
        $item = $menu->get_active;
        $menu->select_item ($item) if $item;


Cheers
Grant

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

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

Torsten Schoenfeld
On Mon, 2007-06-11 at 15:09 +1200, Grant McLean wrote:

> > 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.
>
> Perhaps it might be a good idea to amend the example accordingly:

Yep.  Applied to the stable branch and HEAD of CVS.  Thanks!

--
Bye,
-Torsten

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list