summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rwxr-xr-xbin/net_applet54
2 files changed, 27 insertions, 30 deletions
diff --git a/NEWS b/NEWS
index 76e3f16..c1b679d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+- net_applet:
+ o use DBus Menu (requires StatusNotifier 1.0) (mga#20410)
+
2.29
- net_applet:
o make sure the status icon exists before trying to display it (mga#20425)
diff --git a/bin/net_applet b/bin/net_applet
index 1a0d369..683add7 100755
--- a/bin/net_applet
+++ b/bin/net_applet
@@ -26,11 +26,6 @@ use Gtk3::Notify -init, 'NetApplet';
use ugtk3 qw(:create :helpers :wrappers :dialogs);
use Glib::Object::Introspection;
-Glib::Object::Introspection->setup(
- basename => 'StatusNotifier',
- version => '0.1',
- package => 'StatusNotifier');
-
my $onstartupfile = "$ENV{HOME}/.net_applet";
my $system_file = '/etc/sysconfig/drakx-net';
shouldStart() or die "$onstartupfile should be set to TRUE or use net_applet --force\n";
@@ -237,10 +232,18 @@ my %actions = (
# the deprecated GtkStatusIcon.
if ($ENV{DESKTOP_SESSION} =~ /plasma$/i) {
$is_plasma = 1;
- $icon = StatusNotifier::Notifier->new_from_icon_name('net_applet', 'STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS', 'drakx-net-unconfigured');
+
+ Glib::Object::Introspection->setup(
+ basename => 'StatusNotifier',
+ version => '1.0',
+ package => 'StatusNotifier');
+
+ $icon = StatusNotifier::Item->new_from_icon_name('net_applet', 'STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS', 'drakx-net-unconfigured');
$icon->set_title('net_applet');
$icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE');
$icon->register;
+ # We keep this only as a fallback if the DBusMenu service does not work.
+ # This way, we are sure that right-clicks will always work. (mga#20410)
$icon->signal_connect(context_menu => sub {
$menu->popup(undef, undef, undef, undef, 0, Gtk3::get_current_event_time()) if $menu;
});
@@ -304,6 +307,16 @@ $SIG{USR1} = sub {
eval { $network::net_applet::ifw->get_reports };
};
+# NOTE: Must be called after checkNetworkForce() above to make sure that
+# the menu has already been created, else set_context_menu() will complain.
+# When net_applet is launched automatically when opening a new session, there
+# seems to be some latency with DBus and/or DBusMenu, and when this method
+# is called too early, it seems to be blocked. So we add a timer here to call
+# it again to make sure that right-click events will be correctly handled by
+# DBusMenu. If the registration fails again, then the 'context_menu' signal
+# will be emitted and caught above (mga#20410).
+Glib::Timeout->add(100, sub { $icon->set_context_menu($menu); 0 }) if $is_plasma;
+
# do not create zombies (#20552)
Glib::Timeout->add_seconds(1, sub {
POSIX::sigprocmask(SIG_UNBLOCK, POSIX::SigSet->new(SIGCHLD));
@@ -543,36 +556,16 @@ sub create_action_item {
}
}
-sub empty_menu {
- my ($menu) = @_;
- delete $_->{menuitems} foreach values %wireless_networks;
- $menu->destroy if $menu;
- Gtk3::Menu->new;
-}
-
sub get_wireless_networks_sorted() {
sort {
$b->{current} <=> $a->{current} || $b->{signal_strength} <=> $a->{signal_strength} || $a->{name} cmp $b->{name};
} values %wireless_networks;
}
-sub generate_simple_menu() {
- $simple_menu = empty_menu($simple_menu);
-
- if ($wireless_device) {
- my @networks = get_wireless_networks_sorted();
- my @valuable_networks = splice @networks, 0, 7;
- gtkappend($simple_menu,
- (map { generate_wireless_menuitem($_) } @valuable_networks),
- (@networks ? create_menu(N("More networks"), map { generate_wireless_menuitem($_) } @networks) : ()),
- Gtk3::SeparatorMenuItem->new,
- );
- }
- gtkappend($simple_menu, create_menu_choices('setInterface', 'allow_single_choice'));
-}
-
sub generate_menu() {
- $menu = empty_menu($menu);
+ delete $_->{menuitems} foreach values %wireless_networks;
+ $menu->destroy if $menu;
+ $menu = Gtk3::Menu->new;
my (@settings);
my $interactive;
@@ -612,7 +605,8 @@ sub generate_menu() {
$menu->append(gtkshow(Gtk3::SeparatorMenuItem->new));
$menu->append(create_action_item('help'));
$menu->append(create_action_item('quit'));
- $menu;
+ # As we destroyed the menu before recreating it, we need to attach it again.
+ $icon->set_context_menu($menu) if $is_plasma;
}
sub mainQuit() {
Glib::Source->remove($timeout) if $timeout;