/usr/share/gmusicbrowser/plugins/desktopwidget.pm is in gmusicbrowser 1.1.9-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | # Copyright (C) 2010 Quentin Sculo <squentin@free.fr>
#
# This file is part of Gmusicbrowser.
# Gmusicbrowser is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation
=for gmbplugin DesktopWidgets
name Desktop widgets
title Desktop widgets plugin
desc Open special layouts as desktop widgets
=cut
package GMB::Plugin::DesktopWidgets;
use strict;
use warnings;
use constant
{ OPT => 'PLUGIN_DesktopWidgets_',
};
my $DWlist= $::Options{OPT.'list'} ||= {};
my %Displayed;
my ($OptionsBox,$Treeview,$LayoutCombo);
sub Start
{ Glib::Idle->add( sub { CreateWindow($_) for sort keys %$DWlist; 0; });
}
sub Stop
{ $_->close_window for grep $_, values %Displayed;
%Displayed=();
}
sub prefbox
{ my $vbox=Gtk2::VBox->new(::FALSE, 2);
$LayoutCombo= TextCombo::Tree->new( sub {Layout::get_layout_list('D')}, undef, undef, event=>'Layouts', );
my $layoutlabel= Gtk2::Label->new(_"Layout :");
my $add= ::NewIconButton('gtk-add',_"Add", sub { New($LayoutCombo->get_value); });
my $store=Gtk2::ListStore->new('Glib::String','Glib::Boolean','Glib::String');
$Treeview=Gtk2::TreeView->new($store);
$Treeview->set_size_request(100,($Treeview->create_pango_layout("X")->get_pixel_size)[1]*5.5); #request 5.5 lines of height (not counting row spacing)
$Treeview->set_headers_visible(::FALSE);
my $togglerenderer=Gtk2::CellRendererToggle->new;
$togglerenderer->signal_connect(toggled => \&toggled);
$Treeview->append_column( Gtk2::TreeViewColumn->new_with_attributes( 'active', $togglerenderer, active => 1 ));
my $renderer=Gtk2::CellRendererText->new;
$Treeview->append_column( Gtk2::TreeViewColumn->new_with_attributes( 'name', $renderer, text => 2 ));
my $sw=Gtk2::ScrolledWindow->new;
$sw->set_shadow_type('etched-in');
$sw->set_policy('automatic','automatic');
$sw->add($Treeview);
$Treeview->get_selection->signal_connect(changed => \&selchanged_cb);
$OptionsBox=Gtk2::VBox->new(::FALSE, 2);
$vbox->pack_start($_,::FALSE,::FALSE,2) for ::Hpack( $layoutlabel,$LayoutCombo,$add ),$sw,$OptionsBox;
::weaken($OptionsBox);
::weaken($Treeview);
::weaken($LayoutCombo);
Fill();
return $vbox;
}
sub Fill
{ my $selected=shift;
return unless $Treeview;
my $store=$Treeview->get_model;
$store->clear;
for my $key (sort keys %$DWlist)
{ my $layout= $DWlist->{$key}{layout};
my $name= Layout::get_layout_name($layout);
my $iter=$store->append;
$store->set($iter, 0,$key, 1,!$DWlist->{$key}{dw_inactive}, 2,$name);
$Treeview->get_selection->select_iter($iter) if $selected && $key eq $selected;
}
}
sub Remove
{ my $key=shift;
return unless $key;
delete $DWlist->{$key};
my $window= delete $Displayed{$key};
$window->close_window if $window;
Fill();
}
sub selchanged_cb
{ my $treesel=shift;
$OptionsBox->remove($_) for $OptionsBox->get_children;
my $iter=$treesel->get_selected;
return unless $iter;
my $key=$Treeview->get_model->get($iter,0);
FillOptions($key);
}
sub toggled
{ my ($cell, $path_string)=@_;
my $store=$Treeview->get_model;
my $iter=$store->get_iter_from_string($path_string);
my $key= $store->get($iter,0);
my $state= $DWlist->{$key}{dw_inactive}^=1;
$store->set($iter,1,!$state);
if ($state)
{ my $window= delete $Displayed{$key};
$window->close_window if $window;
}
else { CreateWindow($key); }
}
sub New
{ my $layout=shift;
return unless defined $layout;
my $layoutdef=$Layout::Layouts{$layout};
return unless $layoutdef;
my $key='DesktopWidget000';
$key++ while defined $DWlist->{$key};
my $default_window_opt= ::ParseOptions( $layoutdef->{Window}||'' );
my $size= $default_window_opt->{size} || '1x1';
my ($w,$h)= $size=~m/(\d+)x(\d+)/;
my %opt=
( layout => $layout,
DefaultFontColor=> $layoutdef->{DefaultFontColor} || 'white',
DefaultFont => $layoutdef->{DefaultFont} || 'Sans 12',
below => 1,
opacity => 1,
x => 0,
y => 0,
w => $w||1,
h => $h||1,
);
$DWlist->{$key}= \%opt;
CreateWindow($key);
Fill($key);
}
sub FillOptions
{ my $key=shift;
return unless $OptionsBox;
my $opt= $DWlist->{$key};
my $layout= $opt->{layout};
my $label= Gtk2::Label->new;
my $remove= ::NewIconButton('gtk-remove',_"Remove this widget", sub { Remove($key) });
if ($Layout::Layouts{$layout})
{ my $name= $Layout::Layouts{$layout}{Name} || $layout;
my $author=$Layout::Layouts{$layout}{Author};
my $markup= "<b>%s</b>";
if (defined $author)
{ $author= _("by").' '.$author;
$markup.= "\n<i><small>%s</small></i>";
}
$label->set_markup_with_format($markup,$name, $author||() );
}
else
{ $label->set_markup_with_format("<b>%s</b>",_"The layout for this desktop widget is missing.");
my $vbox= ::Hpack($label, '-',$remove);
$OptionsBox->pack_start($vbox,::FALSE,::FALSE,2);
$OptionsBox->show_all;
return;
}
my $textcolor= Gtk2::ColorButton->new_with_color( Gtk2::Gdk::Color->parse($opt->{DefaultFontColor}) );
$textcolor->signal_connect(color_set=>sub { $opt->{DefaultFontColor}= $_[0]->get_color->to_string; CreateWindow($key); });
#my $set_textcolor= ::NewPrefCheckButton(OPT.'set_textcolor',_"Change default text color", cb=>\&init, widget=>$textcolor, horizontal=>1);
my $textfont= Gtk2::FontButton->new_with_font( $opt->{DefaultFont} );
$textfont->signal_connect(font_set=>sub { $opt->{DefaultFont}= $_[0]->get_font_name; CreateWindow($key); });
my $adjx=Gtk2::Adjustment->new($opt->{x},0,100,1,10,0);
my $adjy=Gtk2::Adjustment->new($opt->{y},0,100,1,10,0);
#my $spinx=Gtk2::SpinButton->new($adjx,0,0);
#my $spiny=Gtk2::SpinButton->new($adjy,0,0);
my $spinx=Gtk2::HScale->new($adjx);
my $spiny=Gtk2::HScale->new($adjy);
$spinx->set_digits(0);
$spiny->set_digits(0);
$adjx->signal_connect(value_changed => sub { $opt->{x}=$_[0]->get_value; MoveWindow($key); });
$adjy->signal_connect(value_changed => sub { $opt->{y}=$_[0]->get_value; MoveWindow($key); });
my $adjo=Gtk2::Adjustment->new($opt->{opacity}*100,0,100,1,10,0);
my $spino=Gtk2::SpinButton->new($adjo,0,0);
$adjo->signal_connect(value_changed => sub { $opt->{opacity}=$_[0]->get_value/100; my $win=$Displayed{$key}; $win->set_opacity($opt->{opacity}) if $win; });
my $ontop=Gtk2::CheckButton->new(_"On top of other windows instead of below");
$ontop->set_active($opt->{ontop});
$ontop->signal_connect(toggled=> sub { my $on=$_[0]->get_active; $opt->{ontop}=$on; $opt->{below}=!$on; CreateWindow($key); });
my $adjw=Gtk2::Adjustment->new($opt->{w},1,::max(2000,$opt->{w},Gtk2::Gdk::Screen->get_default->get_width),10,50,0);
my $adjh=Gtk2::Adjustment->new($opt->{h},1,::max(2000,$opt->{h},Gtk2::Gdk::Screen->get_default->get_height),10,50,0);
my $spinw=Gtk2::SpinButton->new($adjw,0,0);
my $spinh=Gtk2::SpinButton->new($adjh,0,0);
$adjw->signal_connect(value_changed => sub { $opt->{w}=$_[0]->get_value; ResizeWindow($key); });
$adjh->signal_connect(value_changed => sub { $opt->{h}=$_[0]->get_value; ResizeWindow($key); });
my $vbox= ::Vpack(
[ $label, '-',$remove ],
[ Gtk2::Label->new(_"Default text color"), $textcolor],
[ Gtk2::Label->new(_"Default text font"), $textfont],
[ Gtk2::Label->new(_"Centered on"), '_',$spinx, Gtk2::Label->new('% x'), '_',$spiny, Gtk2::Label->new('%') ],
[ Gtk2::Label->new(_"Minimum size"), $spinw, Gtk2::Label->new('x'), $spinh ],
[ Gtk2::Label->new(_"Opacity"), $spino, Gtk2::Label->new('%') ],
$ontop);
$OptionsBox->pack_start($vbox,::FALSE,::FALSE,2);
$OptionsBox->show_all;
}
sub CreateWindow
{ my $key=shift;
my $opt= $DWlist->{$key};
return unless $opt;
return if $opt->{dw_inactive};
delete $opt->{dw_inactive};
my $pos= $opt->{x}.'%x'.$opt->{y}.'%';
my $size= $opt->{w}.'x'.$opt->{h};
$Displayed{$key}= Layout::Window->new($opt->{layout}, %$opt, 'pos'=>$pos, size=>$size, uniqueid=>$key, ifexist=>'replace',
fallback=> 'NONE', nodecoration=>1, skippager=>1, skiptaskbar=>1, sticky=>1,
typehint=>'dock',
);
}
sub MoveWindow
{ my $key=shift;
my $win=$Displayed{$key};
return unless $win;
$win->{'pos'}= $DWlist->{$key}{x}.'%x'.$DWlist->{$key}{y}.'%';
my ($x,$y)=$win->Position;
$win->move($x,$y);
}
sub ResizeWindow
{ my $key=shift;
my $win=$Displayed{$key};
return unless $win;
CreateWindow($key);
#$win->resize($DWlist->{$key}{w},$DWlist->{$key}{h}); #better, but doesn't work well with Cover widget
}
1
|