obmenu
This commit is contained in:
		
							parent
							
								
									558caf9e95
								
							
						
					
					
						commit
						3a69a24fbc
					
				
					 4 changed files with 5 additions and 756 deletions
				
			
		| 
						 | 
				
			
			@ -1,626 +0,0 @@
 | 
			
		|||
#!/usr/bin/perl
 | 
			
		||||
 | 
			
		||||
# Copyright (C) 2011-2016 Daniel "Trizen" Șuteu <echo dHJpemVueEBnbWFpbC5jb20K | base64 -d>.
 | 
			
		||||
#
 | 
			
		||||
# This program is free software: you can redistribute it and/or modify
 | 
			
		||||
# it under the terms of the GNU General Public License as published by
 | 
			
		||||
# the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
# (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
# This program is distributed in the hope that it will be useful,
 | 
			
		||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
# GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License
 | 
			
		||||
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
# Openbox Menu Generator
 | 
			
		||||
# A fast pipe/static menu generator for the Openbox Window Manager.
 | 
			
		||||
 | 
			
		||||
# Edited on 07 December 2014 by Bob Currey
 | 
			
		||||
#   added cmd line option -t "Menu Label Text" with default of "Applications"
 | 
			
		||||
 | 
			
		||||
# Program: obmenu-generator
 | 
			
		||||
# License: GPLv3
 | 
			
		||||
# Created on: 25 March 2011
 | 
			
		||||
# Latest edit on: 09 February 2016
 | 
			
		||||
# Website: https://github.com/trizen/obmenu-generator
 | 
			
		||||
 | 
			
		||||
#use 5.014;
 | 
			
		||||
#use strict;
 | 
			
		||||
#use warnings;
 | 
			
		||||
 | 
			
		||||
require Linux::DesktopFiles;    # >= 0.09
 | 
			
		||||
 | 
			
		||||
my $pkgname = 'obmenu-generator';
 | 
			
		||||
my $surum = 0.66;
 | 
			
		||||
 | 
			
		||||
our ($CONFIG, $SCHEMA);
 | 
			
		||||
my $output_h = \*STDOUT;
 | 
			
		||||
 | 
			
		||||
my ($pipe, $static, $icons, $reconfigure, $update_config, $reconf_openbox);
 | 
			
		||||
 | 
			
		||||
my $home_dir =
 | 
			
		||||
     $ENV{HOME}
 | 
			
		||||
  || $ENV{LOGDIR}
 | 
			
		||||
  || (getpwuid($<))[7]
 | 
			
		||||
  || `echo -n ~`;
 | 
			
		||||
 | 
			
		||||
my $xdg_config_home = "$home_dir/.config";
 | 
			
		||||
 | 
			
		||||
my $menu_id         = "root-menu";
 | 
			
		||||
my $menu_label_text = "Applications";
 | 
			
		||||
my $config_dir      = "$xdg_config_home/$pkgname";
 | 
			
		||||
my $schema_file     = "$config_dir/schema.pl";
 | 
			
		||||
my $config_file     = "$config_dir/config.pl";
 | 
			
		||||
my $openbox_conf    = "$xdg_config_home/openbox";
 | 
			
		||||
my $menufile        = "$openbox_conf/menu.xml";
 | 
			
		||||
my $icons_db        = "$config_dir/icons.db";
 | 
			
		||||
my $cache_db        = "$config_dir/cache.db";
 | 
			
		||||
 | 
			
		||||
sub usage {
 | 
			
		||||
    print <<"HELP";
 | 
			
		||||
usage: $0 [options]
 | 
			
		||||
 | 
			
		||||
options:
 | 
			
		||||
    -p         : (re)generate a pipe menu
 | 
			
		||||
    -s         : (re)generate a static menu
 | 
			
		||||
    -i         : include icons in menus
 | 
			
		||||
    -m <id>    : menu id (default: 'root-menu')
 | 
			
		||||
    -t <label> : menu label text (default: 'Applications')
 | 
			
		||||
 | 
			
		||||
other:
 | 
			
		||||
    -S <file>  : path to the schema.pl file
 | 
			
		||||
    -C <file>  : path to the config.pl file
 | 
			
		||||
    -o <file>  : path to the menu.xml file
 | 
			
		||||
    -u         : update the config file
 | 
			
		||||
    -r         : regenerate the config file
 | 
			
		||||
    -d         : regenerate icons.db
 | 
			
		||||
    -c         : reconfigure openbox automatically
 | 
			
		||||
    -R         : reconfigure openbox and exit
 | 
			
		||||
 | 
			
		||||
Help:
 | 
			
		||||
    -h  : print this message and exit
 | 
			
		||||
    -v  : print version and exit
 | 
			
		||||
 | 
			
		||||
Examples:
 | 
			
		||||
   ** Static menu without icons:
 | 
			
		||||
        $0 -s -c
 | 
			
		||||
 | 
			
		||||
   ** Dynamic menu with icons:
 | 
			
		||||
        $0 -p -i
 | 
			
		||||
 | 
			
		||||
** Config file: $config_file
 | 
			
		||||
** Schema file: $schema_file
 | 
			
		||||
HELP
 | 
			
		||||
    exit 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my $config_help = <<"HELP";
 | 
			
		||||
 | 
			
		||||
|| FILTERING
 | 
			
		||||
    | skip_filename_re    : Skip a .desktop file if its name matches the regex.
 | 
			
		||||
                            Name is from the last slash to the end. (filename.desktop)
 | 
			
		||||
                            Example: qr/^(?:gimp|xterm)\\b/,    # skips 'gimp' and 'xterm'
 | 
			
		||||
 | 
			
		||||
    | skip_entry          : Skip a destkop file if the value from a given key matches the regex.
 | 
			
		||||
                            Example: [
 | 
			
		||||
                                {key => 'Name', re => qr/(?:about|terminal)/i},
 | 
			
		||||
                                {key => 'Exec', re => qr/^xterm/},
 | 
			
		||||
                            ],
 | 
			
		||||
 | 
			
		||||
    | substitutions       : Substitute, by using a regex, in the values of the desktop files.
 | 
			
		||||
                            Example: [
 | 
			
		||||
                                {key => 'Exec', re => qr/xterm/, value => 'sakura'},
 | 
			
		||||
                                {key => 'Exec', re => qr/\\\\\\\\/,  value => '\\\\', global => 1},    # for wine apps
 | 
			
		||||
                            ],
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
|| ICON SETTINGS
 | 
			
		||||
    | icon_dirs_first     : When looking for icons, look in this directories first,
 | 
			
		||||
                            before looking in the directories of the current icon theme.
 | 
			
		||||
                            Example: [
 | 
			
		||||
                                "\$ENV{HOME}/My icons",
 | 
			
		||||
                            ],
 | 
			
		||||
 | 
			
		||||
    | icon_dirs_second    : Look in this directories after looked in the directories of the
 | 
			
		||||
                            current icon theme. (Before /usr/share/pixmaps)
 | 
			
		||||
                            Example: [
 | 
			
		||||
                                "/usr/share/icons/gnome",
 | 
			
		||||
                            ],
 | 
			
		||||
 | 
			
		||||
    | icon_dirs_last      : Look in this directories at the very last, after looked in
 | 
			
		||||
                            /usr/share/pixmaps, /usr/share/icons/hicolor and some other
 | 
			
		||||
                            directories.
 | 
			
		||||
                            Example: [
 | 
			
		||||
                                "/usr/share/icons/Tango",
 | 
			
		||||
                            ],
 | 
			
		||||
 | 
			
		||||
    | strict_icon_dirs    : A true value will make the script to look only inside the directories
 | 
			
		||||
                            specified by you in either one of the above three options.
 | 
			
		||||
 | 
			
		||||
    | gtk_rc_filename     : Absolute path to the GTK configuration file.
 | 
			
		||||
    | missing_image       : Use this icon for missing icons (default: gtk-missing-image)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
|| KEYS
 | 
			
		||||
    | name_keys           : Valid keys for the item names.
 | 
			
		||||
                            Example: ['Name[fr]', 'GenericName[fr]', 'Name'],   # french menu
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
|| PATHS
 | 
			
		||||
    | desktop_files_paths   : Absolute paths which contain .desktop files.
 | 
			
		||||
                              Example: [
 | 
			
		||||
                                '/usr/share/applications',
 | 
			
		||||
                                "\$ENV{HOME}/.local/share/applications",
 | 
			
		||||
                                glob("\$ENV{HOME}/.local/share/applications/wine/Programs/*"),
 | 
			
		||||
                              ],
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
|| NOTES
 | 
			
		||||
    | Regular expressions:
 | 
			
		||||
        * use qr/RE/ instead of 'RE'
 | 
			
		||||
        * use qr/RE/i for case insensitive mode
 | 
			
		||||
HELP
 | 
			
		||||
 | 
			
		||||
if (@ARGV) {
 | 
			
		||||
    while (defined(my $arg = shift @ARGV)) {
 | 
			
		||||
        if ($arg eq '-i') {
 | 
			
		||||
            $icons = 1;
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-p') {
 | 
			
		||||
            $pipe = 1;
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-r') {
 | 
			
		||||
            $reconfigure = 1;
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-s') {
 | 
			
		||||
            $static = 1;
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-d') {
 | 
			
		||||
            unlink $icons_db;
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-u') {
 | 
			
		||||
            $update_config = 1;
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-v') {
 | 
			
		||||
            print "$pkgname $surum\n";
 | 
			
		||||
            exit 0;
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-c') {
 | 
			
		||||
            $reconf_openbox = 1;
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-R') {
 | 
			
		||||
            exec 'openbox', '--reconfigure';
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-S') {
 | 
			
		||||
            $schema_file = shift(@ARGV) // die "$0: option '-S' requires an argument!\n";
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-C') {
 | 
			
		||||
            $config_file = shift(@ARGV) // die "$0: options '-C' requires an argument!\n";
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-o') {
 | 
			
		||||
            $menufile = shift(@ARGV) // die "$0: option '-o' requires an argument!\n";
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-m') {
 | 
			
		||||
            $menu_id = shift(@ARGV) // die "$0: option '-m' requires an argument!\n";
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-t') {
 | 
			
		||||
            $menu_label_text = shift(@ARGV) // die "$0: option '-t' requires an argument!\n";
 | 
			
		||||
        }
 | 
			
		||||
        elsif ($arg eq '-h') {
 | 
			
		||||
            usage();
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            die "$0: option `$arg' is invalid!\n";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (not -d $config_dir) {
 | 
			
		||||
    require File::Path;
 | 
			
		||||
    File::Path::make_path($config_dir)
 | 
			
		||||
      or die "Can't create directory '${config_dir}': $!";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my $config_documentation = <<"EOD";
 | 
			
		||||
#!/usr/bin/perl
 | 
			
		||||
 | 
			
		||||
# $pkgname - configuration file
 | 
			
		||||
# This file will be updated automatically.
 | 
			
		||||
# Any additional comment and/or indentation will be lost.
 | 
			
		||||
 | 
			
		||||
=for comment
 | 
			
		||||
$config_help
 | 
			
		||||
=cut
 | 
			
		||||
 | 
			
		||||
EOD
 | 
			
		||||
 | 
			
		||||
my %CONFIG = (
 | 
			
		||||
    'Linux::DesktopFiles' => {
 | 
			
		||||
 | 
			
		||||
        keep_unknown_categories => 1,
 | 
			
		||||
        unknown_category_key    => 'other',
 | 
			
		||||
        gtk_rc_filename         => "$home_dir/.gtkrc-2.0",
 | 
			
		||||
 | 
			
		||||
        skip_entry       => undef,
 | 
			
		||||
        substitutions    => undef,
 | 
			
		||||
        skip_filename_re => undef,
 | 
			
		||||
 | 
			
		||||
        terminalize            => 1,
 | 
			
		||||
        terminalization_format => q{%s -e '%s'},
 | 
			
		||||
 | 
			
		||||
        desktop_files_paths => ['/usr/share/applications', '/usr/local/share/applications'],
 | 
			
		||||
 | 
			
		||||
        icon_dirs_first  => undef,
 | 
			
		||||
        icon_dirs_second => undef,
 | 
			
		||||
        icon_dirs_last   => undef,
 | 
			
		||||
        strict_icon_dirs => undef,
 | 
			
		||||
 | 
			
		||||
        skip_svg_icons => 0,
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    name_keys    => ['Name'],
 | 
			
		||||
    terminal     => 'xterm',
 | 
			
		||||
    editor       => 'geany',
 | 
			
		||||
    missing_icon => 'gtk-missing-image',
 | 
			
		||||
    VERSION      => $surum,
 | 
			
		||||
             );
 | 
			
		||||
 | 
			
		||||
sub dump_configuration {
 | 
			
		||||
    require Data::Dump;
 | 
			
		||||
    open my $config_fh, '>', $config_file
 | 
			
		||||
      or die "Can't open file '${config_file}' for write: $!";
 | 
			
		||||
    my $dumped_config = q{our $CONFIG = } . Data::Dump::dump(\%CONFIG);
 | 
			
		||||
    print $config_fh $config_documentation, $dumped_config;
 | 
			
		||||
    close $config_fh;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (not -e $config_file or $reconfigure) {
 | 
			
		||||
    dump_configuration();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (not -e $schema_file) {
 | 
			
		||||
    if (-e (my $etc_schema_file = "/etc/xdg/$pkgname/schema.pl")) {
 | 
			
		||||
        require File::Copy;
 | 
			
		||||
        File::Copy::copy($etc_schema_file, $schema_file)
 | 
			
		||||
          or die "Can't copy file `$etc_schema_file' to `$schema_file': $!";
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        die "$0: schema file `$schema_file' does not exists!\n";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
require $schema_file;    # Load the configuration files
 | 
			
		||||
 | 
			
		||||
# Remove user's defined values
 | 
			
		||||
my @valid_keys = grep exists $CONFIG{$_}, keys %{$CONFIG};
 | 
			
		||||
@CONFIG{@valid_keys} = @{$CONFIG}{@valid_keys};
 | 
			
		||||
 | 
			
		||||
# Keep user's defined values
 | 
			
		||||
#@CONFIG{keys %{$CONFIG}} = values %{$CONFIG};
 | 
			
		||||
 | 
			
		||||
if ($CONFIG{VERSION} != $surum) {
 | 
			
		||||
    $update_config = 1;
 | 
			
		||||
    $CONFIG{VERSION} = $surum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (!$pipe) {
 | 
			
		||||
 | 
			
		||||
    # Performance improvement
 | 
			
		||||
    # XXX: don't do this in production code!
 | 
			
		||||
    @INC{
 | 
			
		||||
        qw(
 | 
			
		||||
          strict.pm
 | 
			
		||||
          warnings.pm
 | 
			
		||||
          Tie/Hash.pm
 | 
			
		||||
          Carp.pm
 | 
			
		||||
          Exporter.pm
 | 
			
		||||
          warnings/register.pm
 | 
			
		||||
          )
 | 
			
		||||
        } = ();
 | 
			
		||||
 | 
			
		||||
    *warnings::warnif = sub { };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Regenerate the cache db if the config or schema file has been modified
 | 
			
		||||
if ((-M $config_file) < (-M $cache_db) or (-M _) > (-M $schema_file)) {
 | 
			
		||||
    print STDERR "** Regenerating the cache DB...\n";
 | 
			
		||||
    unlink $cache_db;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
require GDBM_File;
 | 
			
		||||
tie my %desktop_file, 'GDBM_File', $cache_db, &GDBM_File::GDBM_WRCREAT, 0640;
 | 
			
		||||
 | 
			
		||||
{    # Regerate the icon db if the gtkrc file has been modified
 | 
			
		||||
    my $gtkrc_mtime = (stat $CONFIG{'Linux::DesktopFiles'}{gtk_rc_filename})[9];
 | 
			
		||||
 | 
			
		||||
    if (exists $desktop_file{__GTKRC_MTIME__}) {
 | 
			
		||||
        if ($desktop_file{__GTKRC_MTIME__} != $gtkrc_mtime) {
 | 
			
		||||
            print STDERR "** Regenerating the icons DB...\n";
 | 
			
		||||
            unlink $icons_db;
 | 
			
		||||
            $desktop_file{__GTKRC_MTIME__} = $gtkrc_mtime;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        $desktop_file{__GTKRC_MTIME__} = $gtkrc_mtime;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my $desk_obj = Linux::DesktopFiles->new(
 | 
			
		||||
    %{$CONFIG{'Linux::DesktopFiles'}},
 | 
			
		||||
 | 
			
		||||
    home_dir => $home_dir,
 | 
			
		||||
 | 
			
		||||
    categories   => [map $_->{cat}[0], grep exists $_->{cat}, @$SCHEMA],
 | 
			
		||||
    keys_to_keep => [@{$CONFIG{name_keys}},
 | 
			
		||||
                     'Exec', 'Icon',
 | 
			
		||||
                     (
 | 
			
		||||
                      defined($CONFIG{'Linux::DesktopFiles'}{skip_entry})
 | 
			
		||||
                        && ref($CONFIG{'Linux::DesktopFiles'}{skip_entry}) eq 'ARRAY'
 | 
			
		||||
                      ? (map { $_->{key} } @{$CONFIG{'Linux::DesktopFiles'}{skip_entry}})
 | 
			
		||||
                      : ()
 | 
			
		||||
                     ),
 | 
			
		||||
                    ],
 | 
			
		||||
 | 
			
		||||
    $icons
 | 
			
		||||
    ? (
 | 
			
		||||
       abs_icon_paths   => 1,
 | 
			
		||||
       icon_db_filename => $icons_db,
 | 
			
		||||
      )
 | 
			
		||||
    : (),
 | 
			
		||||
 | 
			
		||||
    terminal              => $CONFIG{terminal},
 | 
			
		||||
    keep_empty_categories => 0,
 | 
			
		||||
    case_insensitive_cats => 1,
 | 
			
		||||
                                       );
 | 
			
		||||
 | 
			
		||||
if ($pipe or $static) {
 | 
			
		||||
    my $menu_backup = $menufile . '.bak';
 | 
			
		||||
    if (not -e $menu_backup and -e $menufile) {
 | 
			
		||||
        require File::Copy;
 | 
			
		||||
        File::Copy::copy($menufile, $menu_backup);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ($static) {
 | 
			
		||||
        open $output_h, '>', $menufile
 | 
			
		||||
          or die "Can't open file '${menufile}' for write: $!";
 | 
			
		||||
    }
 | 
			
		||||
    elsif ($pipe) {
 | 
			
		||||
        if (not -d $openbox_conf) {
 | 
			
		||||
            require File::Path;
 | 
			
		||||
            File::Path::make_path($openbox_conf)
 | 
			
		||||
              or die "Can't create directory '${openbox_conf}': $!";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        require Cwd;
 | 
			
		||||
        my $exec_name = Cwd::abs_path($0) . ($icons ? q{ -i} : q{});
 | 
			
		||||
 | 
			
		||||
        if (not -x $exec_name) {
 | 
			
		||||
            $exec_name = "$^X $exec_name";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        open my $fh, '>', $menufile
 | 
			
		||||
          or die "Can't open file '${menufile}' for write: $!";
 | 
			
		||||
        print $fh <<"PIPE_MENU_HEADER";
 | 
			
		||||
<?xml surum="1.0" encoding="utf-8"?>
 | 
			
		||||
<openbox_menu xmlns="http://openbox.org/"
 | 
			
		||||
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
  xsi:schemaLocation="http://openbox.org/">
 | 
			
		||||
    <menu id="$menu_id" label="$pkgname" execute="$exec_name" />
 | 
			
		||||
</openbox_menu>
 | 
			
		||||
PIPE_MENU_HEADER
 | 
			
		||||
        close $fh;
 | 
			
		||||
 | 
			
		||||
        print STDERR <<'EOT';
 | 
			
		||||
** A dynamic menu has been successfully generated!
 | 
			
		||||
EOT
 | 
			
		||||
 | 
			
		||||
        exec 'openbox', '--reconfigure';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my $generated_menu = $static
 | 
			
		||||
  ? <<"STATIC_MENU_HEADER"
 | 
			
		||||
<?xml surum="1.0" encoding="utf-8"?>
 | 
			
		||||
<openbox_menu xmlns="http://openbox.org/"
 | 
			
		||||
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
  xsi:schemaLocation="http://openbox.org/">
 | 
			
		||||
  <menu id="$menu_id" label="$menu_label_text">
 | 
			
		||||
STATIC_MENU_HEADER
 | 
			
		||||
  : "<openbox_pipe_menu>\n";
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    my %cache;
 | 
			
		||||
 | 
			
		||||
    sub check_icon {
 | 
			
		||||
        $_[0] // return '';
 | 
			
		||||
        $cache{$_[0]} //= ((chr ord($_[0]) eq '/') ? $_[0] : $desk_obj->get_icon_path($_[0])
 | 
			
		||||
                           || $desk_obj->get_icon_path($CONFIG{missing_icon}));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub begin_category {
 | 
			
		||||
    $icons
 | 
			
		||||
      ? <<"MENU_WITH_ICON"
 | 
			
		||||
  <menu id="$_[0]" icon="${\check_icon($_[1])}" label="$_[0]">
 | 
			
		||||
MENU_WITH_ICON
 | 
			
		||||
      : <<"MENU"
 | 
			
		||||
  <menu id="$_[0]" label="$_[0]">
 | 
			
		||||
MENU
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my %categories;
 | 
			
		||||
foreach my $file ($desk_obj->get_desktop_files) {
 | 
			
		||||
 | 
			
		||||
    my %info;
 | 
			
		||||
    if (exists $desktop_file{$file}) {
 | 
			
		||||
        %info = split("\0\1\0", $desktop_file{$file}, -1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    next if exists $info{__IGNORE__};
 | 
			
		||||
 | 
			
		||||
    my $mtime = (stat $file)[9];
 | 
			
		||||
    my $cache_ok = (%info and $info{__MTIME__} == $mtime);
 | 
			
		||||
 | 
			
		||||
    if (not $cache_ok) {
 | 
			
		||||
        $desk_obj->parse(\my %cats, $file);
 | 
			
		||||
 | 
			
		||||
        my $fields = %cats ? (values %cats)[0][0] : {__IGNORE__ => 1};
 | 
			
		||||
        %info = (%{$fields}, __MTIME__ => $mtime);
 | 
			
		||||
 | 
			
		||||
        $info{__CATEGORIES__} = join(';', keys %cats);
 | 
			
		||||
        $desktop_file{$file} = join("\0\1\0", %info);
 | 
			
		||||
 | 
			
		||||
        next if exists $info{__IGNORE__};
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    foreach my $category (split(/;/, $info{__CATEGORIES__})) {
 | 
			
		||||
        push @{$categories{$category}}, \%info;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my %entities = (
 | 
			
		||||
                '&' => '&',
 | 
			
		||||
                '"' => '"',
 | 
			
		||||
                '_' => '__',
 | 
			
		||||
               );
 | 
			
		||||
 | 
			
		||||
foreach my $schema (@$SCHEMA) {
 | 
			
		||||
    if (exists $schema->{cat}) {
 | 
			
		||||
        exists($categories{my $category = lc($schema->{cat}[0]) =~ tr/_a-z0-9/_/cr}) || next;
 | 
			
		||||
        $generated_menu .= begin_category($schema->{cat}[1], ($icons ? $schema->{cat}[2] : ())) . join(
 | 
			
		||||
            q{},
 | 
			
		||||
            (
 | 
			
		||||
             map $_->[1],
 | 
			
		||||
             sort { $a->[0] cmp $b->[0] }
 | 
			
		||||
               map [lc($_) => $_],
 | 
			
		||||
             map {
 | 
			
		||||
 | 
			
		||||
                 my $isim;
 | 
			
		||||
                 my $exec = $_->{Exec};
 | 
			
		||||
 | 
			
		||||
                 foreach my $key (@{$CONFIG{name_keys}}) {
 | 
			
		||||
                     if ($_->{$key}) {
 | 
			
		||||
                         $isim = $_->{$key};
 | 
			
		||||
                         last;
 | 
			
		||||
                     }
 | 
			
		||||
                 }
 | 
			
		||||
 | 
			
		||||
                 # encode the entities
 | 
			
		||||
                 $isim =~ tr/"&_//
 | 
			
		||||
                   && $isim =~ s/([&"_])/$entities{$1}/g;
 | 
			
		||||
 | 
			
		||||
                 $icons
 | 
			
		||||
                   ? <<"ITEM_WITH_ICON"
 | 
			
		||||
    <item label="$isim" icon="${\check_icon($_->{Icon})}"><action isim="Execute"><command><![CDATA[$exec]]></command></action></item>
 | 
			
		||||
ITEM_WITH_ICON
 | 
			
		||||
                   : <<"ITEM";
 | 
			
		||||
    <item label="$isim"><action isim="Execute"><command><![CDATA[$exec]]></command></action></item>
 | 
			
		||||
ITEM
 | 
			
		||||
 | 
			
		||||
               } @{$categories{$category}}
 | 
			
		||||
            )
 | 
			
		||||
          )
 | 
			
		||||
          . qq[  </menu>\n];
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{item}) {
 | 
			
		||||
        my ($command, $label, $icon) = @{$schema->{item}};
 | 
			
		||||
        $generated_menu .= $icons
 | 
			
		||||
          ? <<"ITEM_WITH_ICON"
 | 
			
		||||
    <item label="$label" icon="${\check_icon($icon)}"><action isim="Execute"><command><![CDATA[$command]]></command></action></item>
 | 
			
		||||
ITEM_WITH_ICON
 | 
			
		||||
          : <<"ITEM";
 | 
			
		||||
    <item label="$label"><action isim="Execute"><command><![CDATA[$command]]></command></action></item>
 | 
			
		||||
ITEM
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{sep}) {
 | 
			
		||||
        $generated_menu .=
 | 
			
		||||
          defined($schema->{sep})
 | 
			
		||||
          ? qq[  <separator label="$schema->{sep}"/>\n]
 | 
			
		||||
          : qq[  <separator/>\n];
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{begin_cat}) {
 | 
			
		||||
        $generated_menu .= begin_category(@{$schema->{begin_cat}});
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{end_cat}) {
 | 
			
		||||
        $generated_menu .= qq[  </menu>\n];
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{exit}) {
 | 
			
		||||
        my ($label, $icon) = @{$schema->{exit}};
 | 
			
		||||
        $generated_menu .= $icons
 | 
			
		||||
          ? <<"EXIT_WITH_ICON"
 | 
			
		||||
    <item label="$label" icon="${\check_icon($icon)}"><action isim="Exit"/></item>
 | 
			
		||||
EXIT_WITH_ICON
 | 
			
		||||
          : <<"EXIT";
 | 
			
		||||
    <item label="$label"><action isim="Exit"/></item>
 | 
			
		||||
EXIT
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{raw}) {
 | 
			
		||||
        $generated_menu .= qq[    $schema->{raw}\n];
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{file}) {
 | 
			
		||||
        sysopen(my $fh, $schema->{file}, 0) or die "Can't open file <<$schema->{file}>>: $!";
 | 
			
		||||
        sysread($fh, $generated_menu, -s $schema->{file}, length($generated_menu));
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{pipe}) {
 | 
			
		||||
        my ($command, $label, $icon) = @{$schema->{pipe}};
 | 
			
		||||
        $generated_menu .= $icons
 | 
			
		||||
          ? <<"PIPE_WITH_ICON"
 | 
			
		||||
    <menu id="$label" label="$label" execute="$command" icon="${\check_icon($icon)}"/>
 | 
			
		||||
PIPE_WITH_ICON
 | 
			
		||||
          : <<"PIPE";
 | 
			
		||||
    <menu id="$label" label="$label" execute="$command"/>
 | 
			
		||||
PIPE
 | 
			
		||||
    }
 | 
			
		||||
    elsif (exists $schema->{obgenmenu}) {
 | 
			
		||||
        my ($isim, $icon) = ref($schema->{obgenmenu}) eq 'ARRAY' ? @{$schema->{obgenmenu}} : $schema->{obgenmenu};
 | 
			
		||||
        $generated_menu .= ($icons ? <<"CONFIG_MENU_WITH_ICON" : <<"CONFIG_MENU") . <<'RECONFIGURE';
 | 
			
		||||
  <menu id="$isim" label="$isim" icon="${\check_icon($icon)}">
 | 
			
		||||
CONFIG_MENU_WITH_ICON
 | 
			
		||||
  <menu id="$isim" label="$isim">
 | 
			
		||||
CONFIG_MENU
 | 
			
		||||
    <item label="Reconfigure Openbox"><action isim="Reconfigure" /></item>
 | 
			
		||||
RECONFIGURE
 | 
			
		||||
 | 
			
		||||
        -e '/usr/bin/obconf' && ($generated_menu .= <<'EOL');
 | 
			
		||||
    <item label="Openbox Configuration Manager"><action isim="Execute"><command>obconf</command></action></item>
 | 
			
		||||
EOL
 | 
			
		||||
 | 
			
		||||
        $generated_menu .= <<"CONFIG_MENU";
 | 
			
		||||
    <item label="Configure autostarted apps"><action isim="Execute"><command><![CDATA[$CONFIG{editor} $openbox_conf/autostart]]></command></action></item>
 | 
			
		||||
    <item label="Edit rc.xml"><action isim="Execute"><command><![CDATA[$CONFIG{editor} $openbox_conf/rc.xml]]></command></action></item>
 | 
			
		||||
    <separator />
 | 
			
		||||
    <item label="Generate a pipe menu"><action isim="Execute"><command><![CDATA[$0 -p]]></command></action></item>
 | 
			
		||||
    <item label="Generate a static menu"><action isim="Execute"><command><![CDATA[$0 -s]]></command></action></item>
 | 
			
		||||
    <item label="Generate a pipe menu with icons"><action isim="Execute"><command><![CDATA[$0 -p -i]]></command></action></item>
 | 
			
		||||
    <item label="Generate a static menu with icons"><action isim="Execute"><command><![CDATA[$0 -s -i]]></command></action></item>
 | 
			
		||||
    <separator />
 | 
			
		||||
    <item label="Edit menu.xml"><action isim="Execute"><command><![CDATA[$CONFIG{editor} $menufile]]></command></action></item>
 | 
			
		||||
    <item label="Edit the schema file"><action isim="Execute"><command><![CDATA[$CONFIG{editor} $schema_file]]></command></action></item>
 | 
			
		||||
    <item label="Edit the configuration file"><action isim="Execute"><command><![CDATA[$CONFIG{editor} $config_file]]></command></action></item>
 | 
			
		||||
    <separator />
 | 
			
		||||
    <item label="Regenerate configuration file"><action isim="Execute"><command><![CDATA[$0 -r]]></command></action></item>
 | 
			
		||||
  </menu>
 | 
			
		||||
CONFIG_MENU
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        warn "$0: Invalid key '", (keys %{$schema})[0], "' in schema file!\n";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
print $output_h $generated_menu, $static
 | 
			
		||||
  ? qq[  </menu>\n</openbox_menu>\n]
 | 
			
		||||
  : qq[</openbox_pipe_menu>\n];
 | 
			
		||||
 | 
			
		||||
dump_configuration() if $update_config;
 | 
			
		||||
 | 
			
		||||
if ($static) {
 | 
			
		||||
    print STDERR <<'EOT';
 | 
			
		||||
** A static menu has been successfully generated!
 | 
			
		||||
EOT
 | 
			
		||||
    if ($reconf_openbox) {
 | 
			
		||||
        exec 'openbox', '--reconfigure';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,10 +0,0 @@
 | 
			
		|||
  git clone git://github.com/trizen/obmenu-generator
 | 
			
		||||
    sudo cp obmenu-generator/obmenu-generator /usr/bin
 | 
			
		||||
    sudo cp -r obmenu-generator/schema.pl ~/.config/obmenu-generator/
 | 
			
		||||
    sudo cpanm Linux::DesktopFiles
 | 
			
		||||
    sudo cpanm Data::Dump
 | 
			
		||||
    sudo chmod 777 /usr/bin/obmenu-generator .
 | 
			
		||||
 | 
			
		||||
To set a dynamical version of the Root Menu, put the following in the terminal:
 | 
			
		||||
 | 
			
		||||
    obmenu-generator -p -i .
 | 
			
		||||
| 
						 | 
				
			
			@ -1,114 +0,0 @@
 | 
			
		|||
#!/usr/bin/perl
 | 
			
		||||
 | 
			
		||||
# obmenu-generator - schema file
 | 
			
		||||
 | 
			
		||||
=for comment
 | 
			
		||||
 | 
			
		||||
    item:      add an item inside the menu               {item => ["command", "label", "icon"]},
 | 
			
		||||
    cat:       add a category inside the menu             {cat => ["name", "label", "icon"]},
 | 
			
		||||
    sep:       horizontal line separator                  {sep => undef}, {sep => "label"},
 | 
			
		||||
    pipe:      a pipe menu entry                         {pipe => ["command", "label", "icon"]},
 | 
			
		||||
    file:      include the content of an XML file        {file => "/path/to/file.xml"},
 | 
			
		||||
    raw:       any XML data supported by Openbox          {raw => q(xml data)},
 | 
			
		||||
    begin_cat: begin of a category                  {begin_cat => ["name", "icon"]},
 | 
			
		||||
    end_cat:   end of a category                      {end_cat => undef},
 | 
			
		||||
    obgenmenu: generic menu settings                {obgenmenu => ["label", "icon"]},
 | 
			
		||||
    exit:      default "Exit" action                     {exit => ["label", "icon"]},
 | 
			
		||||
 | 
			
		||||
=cut
 | 
			
		||||
 | 
			
		||||
# NOTE:
 | 
			
		||||
#    * Keys and values are case sensitive. Keep all keys lowercase.
 | 
			
		||||
#    * ICON can be a either a direct path to an icon or a valid icon name
 | 
			
		||||
#    * Category names are case insensitive. (X-XFCE and x_xfce are equivalent)
 | 
			
		||||
 | 
			
		||||
require "$ENV{HOME}/.config/obmenu-generator/config.pl";
 | 
			
		||||
 | 
			
		||||
## Text editor
 | 
			
		||||
my $editor = $CONFIG->{editor};
 | 
			
		||||
 | 
			
		||||
our $SCHEMA = [
 | 
			
		||||
 | 
			
		||||
    #          COMMAND                 LABEL                ICON
 | 
			
		||||
    {item => ['xdg-open .',        'File Manager',      'file-manager']},
 | 
			
		||||
    {item => ['xterm',             'Terminal',          'terminal']},
 | 
			
		||||
    {item => ['xdg-open http://',  'Web Browser',       'web-browser']},
 | 
			
		||||
    {item => ['gmrun',             'Run command',       'system-run']},
 | 
			
		||||
 | 
			
		||||
    {sep => 'Categories'},
 | 
			
		||||
 | 
			
		||||
    #          NAME            LABEL                ICON
 | 
			
		||||
    {cat => ['utility',     'Accessories', 'applications-utilities']},
 | 
			
		||||
    {cat => ['development', 'Development', 'applications-development']},
 | 
			
		||||
    {cat => ['education',   'Education',   'applications-science']},
 | 
			
		||||
    {cat => ['game',        'Games',       'applications-games']},
 | 
			
		||||
    {cat => ['graphics',    'Graphics',    'applications-graphics']},
 | 
			
		||||
    {cat => ['audiovideo',  'Multimedia',  'applications-multimedia']},
 | 
			
		||||
    {cat => ['network',     'Network',     'applications-internet']},
 | 
			
		||||
    {cat => ['office',      'Office',      'applications-office']},
 | 
			
		||||
    {cat => ['other',       'Other',       'applications-other']},
 | 
			
		||||
    {cat => ['settings',    'Settings',    'applications-accessories']},
 | 
			
		||||
    {cat => ['system',      'System',      'applications-system']},
 | 
			
		||||
 | 
			
		||||
    #{cat => ['qt',          'QT Applications',    'qt4logo']},
 | 
			
		||||
    #{cat => ['gtk',         'GTK Applications',   'gnome-applications']},
 | 
			
		||||
    #{cat => ['x_xfce',      'XFCE Applications',  'applications-other']},
 | 
			
		||||
    #{cat => ['gnome',       'GNOME Applications', 'gnome-applications']},
 | 
			
		||||
    #{cat => ['consoleonly', 'CLI Applications',   'applications-utilities']},
 | 
			
		||||
 | 
			
		||||
    #                  LABEL          ICON
 | 
			
		||||
    #{begin_cat => ['My category',  'cat-icon']},
 | 
			
		||||
    #             ... some items ...
 | 
			
		||||
    #{end_cat   => undef},
 | 
			
		||||
 | 
			
		||||
    #            COMMAND     LABEL        ICON
 | 
			
		||||
    #{pipe => ['obbrowser', 'Disk', 'drive-harddisk']},
 | 
			
		||||
 | 
			
		||||
    ## Generic advanced settings
 | 
			
		||||
    #{sep       => undef},
 | 
			
		||||
    #{obgenmenu => ['Openbox Settings', 'openbox']},
 | 
			
		||||
    #{sep       => undef},
 | 
			
		||||
 | 
			
		||||
    ## Custom advanced settings
 | 
			
		||||
    {sep => undef},
 | 
			
		||||
    {begin_cat => ['Advanced Settings', 'gnome-settings']},
 | 
			
		||||
 | 
			
		||||
        # Configuration files
 | 
			
		||||
        {item => ["$editor ~/.conkyrc",              'Conky RC',    'text-x-source']},
 | 
			
		||||
        {item => ["$editor ~/.config/tint2/tint2rc", 'Tint2 Panel', 'text-x-source']},
 | 
			
		||||
 | 
			
		||||
        # obmenu-generator category
 | 
			
		||||
        {begin_cat => ['Obmenu-Generator', 'menu-editor']},
 | 
			
		||||
            {item => ["$editor ~/.config/obmenu-generator/schema.pl", 'Menu Schema', 'text-x-source']},
 | 
			
		||||
            {item => ["$editor ~/.config/obmenu-generator/config.pl", 'Menu Config', 'text-x-source']},
 | 
			
		||||
 | 
			
		||||
            {sep  => undef},
 | 
			
		||||
            {item => ['obmenu-generator -p',       'Generate a pipe menu',              'menu-editor']},
 | 
			
		||||
            {item => ['obmenu-generator -s -c',    'Generate a static menu',            'menu-editor']},
 | 
			
		||||
            {item => ['obmenu-generator -p -i',    'Generate a pipe menu with icons',   'menu-editor']},
 | 
			
		||||
            {item => ['obmenu-generator -s -i -c', 'Generate a static menu with icons', 'menu-editor']},
 | 
			
		||||
            {sep  => undef},
 | 
			
		||||
 | 
			
		||||
            {item => ['obmenu-generator -d', 'Refresh Icon Set', 'gtk-refresh']},
 | 
			
		||||
        {end_cat => undef},
 | 
			
		||||
 | 
			
		||||
        # Openbox category
 | 
			
		||||
        {begin_cat => ['Openbox', 'openbox']},
 | 
			
		||||
            {item => ['openbox --reconfigure',               'Reconfigure Openbox', 'openbox']},
 | 
			
		||||
            {item => ["$editor ~/.config/openbox/autostart", 'Openbox Autostart',   'shellscript']},
 | 
			
		||||
            {item => ["$editor ~/.config/openbox/rc.xml",    'Openbox RC',          'text-xml']},
 | 
			
		||||
            {item => ["$editor ~/.config/openbox/menu.xml",  'Openbox Menu',        'text-xml']},
 | 
			
		||||
        {end_cat => undef},
 | 
			
		||||
 | 
			
		||||
    {end_cat => undef},
 | 
			
		||||
    {sep => undef},
 | 
			
		||||
 | 
			
		||||
    ## The xscreensaver lock command
 | 
			
		||||
    {item => ['xscreensaver-command -lock', 'Lock', 'lock']},
 | 
			
		||||
 | 
			
		||||
    ## This option uses the default Openbox's action "Exit"
 | 
			
		||||
    {exit => ['Exit', 'exit']},
 | 
			
		||||
 | 
			
		||||
    ## This uses the 'oblogout' menu
 | 
			
		||||
    # {item => ['oblogout', 'Exit', 'exit']},
 | 
			
		||||
]
 | 
			
		||||
| 
						 | 
				
			
			@ -1,17 +1,16 @@
 | 
			
		|||
# Tanım:  openbox menu yapıcı
 | 
			
		||||
# URL:          https://github.com/trizen/obmenu-generator
 | 
			
		||||
# Maintainer:   milisarge
 | 
			
		||||
# URL: https://github.com/trizen/obmenu-generator
 | 
			
		||||
# Paketçi:	milisarge
 | 
			
		||||
# Gerekler:   perl-module-build perl-data-dump perl-linux-desktopfiles 
 | 
			
		||||
# Gerekler: perl-module-build perl-data-dump perl-linux-desktopfiles
 | 
			
		||||
# Grup: sistem 
 | 
			
		||||
 | 
			
		||||
isim=obmenu-generator
 | 
			
		||||
surum=0.84
 | 
			
		||||
devir=1
 | 
			
		||||
kaynak=(https://github.com/trizen/${isim}/archive/${surum}.tar.gz)
 | 
			
		||||
kaynak=(https://github.com/trizen/${isim}/archive/${surum}.tar.gz::${isim}-${surum}.tar.gz)
 | 
			
		||||
 | 
			
		||||
derle() {
 | 
			
		||||
	cd "$isim-$surum"
 | 
			
		||||
    install -Dm755 "$isim" "$PKG/usr/bin/$isim"
 | 
			
		||||
    install -Dm644 "schema.pl" "$PKG/etc/xdg/$isim/schema.pl"
 | 
			
		||||
		
 | 
			
		||||
    install -Dm644 "schema.pl" "$PKG/etc/xdg/$isim/schema.pl"		
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue