summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/net_applet51
-rw-r--r--lib/network/signal_strength.pm4
2 files changed, 35 insertions, 20 deletions
diff --git a/bin/net_applet b/bin/net_applet
index 794f152..76e46f3 100755
--- a/bin/net_applet
+++ b/bin/net_applet
@@ -44,7 +44,7 @@ use mygtk3 qw(gtknew gtkset);
use common;
our ($current_state, $current_interface);
-our ($icon, $icon_file_name);
+our ($icon, $is_plasma);
our $dbus;
our ($interactive_cb, $ifw, $ifw_alert);
@@ -66,22 +66,25 @@ sub get_state_pixbuf {
my $img;
my $wnet = $current_state eq 'connected' && get_current_network();
if ($wnet) {
- ($img, $icon_file_name) = network::signal_strength::get_strength_icon($wnet);
- return $img;
+ return network::signal_strength::get_strength_icon($wnet);
}
else {
# By default, use the big image, and fall back to the small one if it does not exist.
- $icon_file_name = $pixbufs{state}{"${current_state}_big"} ? "${current_state}_big" : $current_state;
- return $pixbufs{state}{$icon_file_name};
+ return $pixbufs{state}{"${current_state}_big"} || $pixbufs{state}{$current_state};
}
}
sub update_tray_icon() {
if (!$ifw_alert) {
- $icon->set_from_pixbuf('STATUS_NOTIFIER_ICON', get_state_pixbuf());
- } else {
- $icon_file_name = mygtk3::_find_imgfile('gtk-dialog-warning');
- $icon->set_from_icon_name('STATUS_NOTIFIER_ICON', $icon_file_name);
+ my @args = $is_plasma ? qw(STATUS_NOTIFIER_ICON) : ();
+ push @args, get_state_pixbuf();
+ $icon->set_from_pixbuf(@args);
+ }
+ elsif ($is_plasma) {
+ $icon->set_from_icon_name('STATUS_NOTIFIER_ICON', 'dialog-warning');
+ }
+ else {
+ $icon->set_from_stock('gtk-dialog-warning');
}
}
@@ -233,14 +236,26 @@ my %actions = (
},
);
+# Plasma supports SNI natively. Other DE do not. In that case, we fall back to
+# 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');
+ $icon->set_title('net_applet');
+ $icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE');
+ $icon->register;
+ $icon->signal_connect(context_menu => sub {
+ $menu->popup(undef, undef, undef, undef, 0, Gtk3::get_current_event_time()) if $menu;
+ });
+}
+else {
+ $icon = Gtk3::StatusIcon->new;
+ $icon->signal_connect(popup_menu => sub {
+ my ($_icon, $button, $time) = @_;
+ $menu->popup(undef, undef, undef, undef, $button, $time) if $menu;
+ });
+}
-$icon = StatusNotifier::Notifier->new_from_icon_name('net_applet', 'STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS', mygtk3::_find_imgfile('connected'));
-$icon->set_title('netapplet');
-$icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE');
-$icon->register;
-$icon->signal_connect(context_menu => sub {
- $menu->popup(undef, undef, undef, undef, 0, Gtk3::get_current_event_time()) if $menu;
- });
$icon->signal_connect(activate => sub {
if ($ifw_alert) {
run_drakids();
@@ -482,7 +497,9 @@ sub update_applet() {
generate_menu();
network::net_applet::update_tray_icon();
- $icon->set_tooltip($icon_file_name, 'net_applet', get_state_message());
+ my $message = get_state_message();
+
+ $is_plasma ? $icon->set_tooltip("drakx-net-$current_state", 'net_applet', $message) : $icon->set_tooltip_text($message);
}
sub create_menu_choices {
diff --git a/lib/network/signal_strength.pm b/lib/network/signal_strength.pm
index 4dd17aa..8a3a5be 100644
--- a/lib/network/signal_strength.pm
+++ b/lib/network/signal_strength.pm
@@ -9,9 +9,7 @@ my %pixbufs;
sub get_strength_icon {
my ($network) = @_;
my $approx = 20 + min(80, int($network->{signal_strength}/20)*20);
- my $file_name = 'wifi-' . sprintf('%03d', $approx);
- $pixbufs{$approx} ||= ugtk3::gtkcreate_pixbuf($file_name);
- return wantarray ? ($pixbufs{$approx}, $file_name) : $pixbufs{$approx};
+ return $pixbufs{$approx} ||= ugtk3::gtkcreate_pixbuf('wifi-' . sprintf('%03d', $approx));
}
1;