#!/usr/bin/perl # Feh-background image changer GUI, raimo 20071116 # wget -O ~/fehbg.txt http://uhvo.org/sec/fehbg.txt # sudo cp ~/fehbg.txt /usr/bin/fehbg # sudo chmod 755 /usr/bin/fehbg # fehbg use strict; use Gtk2 '-init'; my $filename; &check_feh; my $win = Gtk2::Window -> new("toplevel"); $win -> set_position("center"); $win -> set_border_width(0); $win -> set_resizable(0); $win -> signal_connect ("delete_event", sub {Gtk2 -> main_quit}); $win -> set_title("Fehbg"); my $button = Gtk2::Button -> new("Select background image"); $button -> signal_connect("clicked", \&open_dialog); $win -> add($button); $win -> show_all; Gtk2 -> main; exit 0; ##CHECK_FEH sub check_feh{ &dialog("warning", "ok", "Please install Feh first.\nsudo apt-get install feh") if !-x "/usr/bin/feh"; } ##MESSAGE DIALOG sub dialog{ my ($mode, $button, $msg) = @_; my $dialog = Gtk2::MessageDialog -> new($win, [qw/modal destroy-with-parent/], $mode, $button, $msg); my $response = $dialog -> run; $dialog -> destroy; exit 2; } ##OPEN DIALOG sub open_dialog{ my $dialog = Gtk2::FileChooserDialog -> new("Select background image", $win, "open", "gtk-cancel" => "cancel", "gtk-ok" => "ok"); $dialog -> set_do_overwrite_confirmation(1); $dialog -> set_select_multiple(0); $dialog -> signal_connect(selection_changed => sub{$filename = $dialog -> get_filename}); my $response = $dialog -> run; $dialog -> destroy; `feh --bg-scale $filename` if -f $filename; }