diff options
Diffstat (limited to 'mgaapplet')
-rwxr-xr-x | mgaapplet | 52 |
1 files changed, 37 insertions, 15 deletions
@@ -175,13 +175,27 @@ my %actions = ( 'upgrade_distro' => { name => N("Upgrade the system"), launch => \&upgrade }, ); -my $icon = StatusNotifier::Notifier->new_from_icon_name('mgaapplet', 'STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS', 'mgaonline'); -$icon->set_title('mgaapplet'); -$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; - }); +my ($icon, $is_plasma); +# 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('mgaapplet', 'STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS', 'mgaonline'); + $icon->set_title('mgaapplet'); + $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->signal_connect(activate => sub { my %click_actions = ( no_update_medium => \&add_media, @@ -197,7 +211,7 @@ $icon->signal_connect(activate => sub { } $click_actions{$action}->() if ref $click_actions{$action}; - }); + }); foreach my $opt (@ARGV) { if (member($opt, qw(--force -f))) { setAutoStart('TRUE') } if ($opt =~ /--(rpm-root|urpmi-root)=(.*)/) { @@ -491,7 +505,7 @@ sub no_more_supported() { if ($choice eq 'upgrade') { really_confirm_upgrade() and real_upgrade(); } elsif ($choice eq 'nothing') { - $icon->set_status('STATUS_NOTIFIER_STATUS_PASSIVE'); + $is_plasma ? $icon->set_status('STATUS_NOTIFIER_STATUS_PASSIVE') : $icon->set_visible(0); } undef $no_more_supported_wip; } @@ -664,17 +678,25 @@ sub setState { state $previous_state; my @arr = @{$state{$state}{menu}}; my $icon_name = 'mgaonline-' . $state{$state}{colour}[0]; - $icon->set_from_icon_name('STATUS_NOTIFIER_ICON', $icon_name); - $icon->set_tooltip($icon_name, 'mgaapplet', formatAlaTeX(translate($state{$state}{tt}[0]))); - my @invisible_states = qw(delayed okay disconnected locked); + if ($is_plasma) { + $icon->set_from_icon_name('STATUS_NOTIFIER_ICON', $icon_name); + $icon->set_tooltip($icon_name, 'mgaapplet', formatAlaTeX(translate($state{$state}{tt}[0]))); + } + else { + $icon_name = "/usr/share/icons/hicolor/scalable/actions/${icon_name}.svg"; + $icon->set_from_pixbuf(gtkcreate_pixbuf($icon_name)); + $icon->set_tooltip_text(formatAlaTeX(translate($state{$state}{tt}[0]))); + } + my @invisible_states = qw(delayed okay disconnected locked); # do not show icon while checking if previously hidden: if (member($state, @invisible_states) - or $state eq 'busy' && member($previous_state, @invisible_states)) { - $icon->set_status('STATUS_NOTIFIER_STATUS_PASSIVE'); + or $state eq 'busy' && member($previous_state, @invisible_states)) + { + $is_plasma ? $icon->set_status('STATUS_NOTIFIER_STATUS_PASSIVE') : $icon->set_visible(0); } else { - $icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE'); + $is_plasma ? $icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE') : $icon->set_visible(1); } $previous_state = $state; |