Difference between revisions of "Xdg-menu"

From ArchWiki
Jump to: navigation, search
m (Kynikos moved page XdgMenu to Xdg-menu: I don't know if there's a spelling/capitalization better than the others, but at least this one should display the article when searching for "xdg")
m (Configuration: fix template)
 
(18 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
[[Category:Desktop environments]]
 
[[Category:Desktop environments]]
== XDG menu ==
+
[[ja:Xdg-menu]]
 
+
[[ru:Xdg-menu]]
xdg-menu - generates menus for
+
'''xdg-menu''' generates menus for WMs using the [http://standards.freedesktop.org/menu-spec/menu-spec-latest.html Free Desktop menu standard]. You can install {{pkg|archlinux-xdg-menu}} from the [[official repositories]].
  
 +
The following WMs are supported:
 
* twm
 
* twm
 
* ion3
 
* ion3
Line 14: Line 15:
 
* awesome
 
* awesome
  
from XDG stuff. KDE, Gnome, Xfce, Enlightenment are already XDG compatible. For further information see:
+
KDE, Gnome, Xfce, Enlightenment are already XDG compatible.
* [http://standards.freedesktop.org/menu-spec/menu-spec-latest.html Free Desktop menu standard]
+
* {{Pkg|archlinux-xdg-menu}} package in [community]
+
  
=== WM Menu hierarchy ===
+
=== Menu hierarchy ===
 
* Applications
 
* Applications
 
** Accessibility
 
** Accessibility
Line 37: Line 36:
 
Xdg_menu relies on three sets of information to generate menus: a root menu or in other words an XML menu template generally passed on the command line, information cached when it was last run, and a series of configuration files.  
 
Xdg_menu relies on three sets of information to generate menus: a root menu or in other words an XML menu template generally passed on the command line, information cached when it was last run, and a series of configuration files.  
  
* You can find some XML menu templates in /etc/xdg/menus.
+
* You can find some XML menu templates in {{ic|/etc/xdg/menus}}.
* If altering the code in xdg_menu to change layout, make sure you delete everything in ~/.xdg_menu_cache or you will spend hours trying to figure out why your changes to the perl script don't take.
+
* If altering the code in xdg_menu to change layout, make sure you delete everything in {{ic|~/.xdg_menu_cache}} or you will spend hours trying to figure out why your changes to the perl script don't take.
* You can find individual application configurations in /usr/share/applications
+
* You can find individual application configurations in {{ic|/usr/share/applications}}
  
Other configuration file directories can be found under /usr/share. In most cases you will not need to touch these. However if you want to change how your menu is layed out you can alter the menu template for minor changes. Major changes require tweaking the actual xdg_menu perl script. If you find that applications do not appear or that they are called strange things, then you will need to look at the .desktop file in /usr/share/applications. Check this [http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html standards file ].
+
Other configuration file directories can be found under {{ic|/usr/share}}. In most cases you will not need to touch these. However if you want to change how your menu is layed out you can alter the menu template for minor changes. Major changes require tweaking the actual xdg_menu perl script. If you find that applications do not appear or that they are called strange things, then you will need to look at the .desktop file in {{ic|/usr/share/applications}}. Check this [http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html standards file ].
 +
 
 +
=== Adding desktop entries from other directories ===
 +
 
 +
By default, the Xdg-menu will be populated with applications which install their desktop entries to {{ic|/usr/share/applications}}. To add applications to the menu which install their desktop entry to a user folder such as {{ic|~/.local/share/applications}}, edit the {{ic|/etc/xdg/menus/arch-applications.menu}} file and add an {{ic|<AppDir>}} tag for the relevant directory, see below:
 +
 
 +
{{hc|/etc/xdg/menus/arch-applications.menu|
 +
<Menu>
 +
 
 +
  <Name>Applications</Name>
 +
  <Directory>Arch-Applications.directory</Directory>
 +
  <DefaultAppDirs/>
 +
  '''<AppDir>/home/''username''/.local/share/applications</AppDir>'''
 +
  <DefaultDirectoryDirs/>
 +
  <DefaultMergeDirs/>
 +
  ...
 +
}}
  
 
== Usage ==
 
== Usage ==
Line 56: Line 71:
 
        possible formats: twm, WindowMaker, fvwm2, icewm, ion3
 
        possible formats: twm, WindowMaker, fvwm2, icewm, ion3
 
                          blackbox, fluxbox, openbox,  
 
                          blackbox, fluxbox, openbox,  
  xfce4, openbox3, openbox3-pipe,
+
  xfce4, openbox3, openbox3-pipe, awesome
 
  readable
 
  readable
 
default: WindowMaker
 
default: WindowMaker
Line 86: Line 101:
 
<b>update-menus</B> updates WMs menus from XDG stuff and can do it automaticaly using config.  
 
<b>update-menus</B> updates WMs menus from XDG stuff and can do it automaticaly using config.  
  
This is a script wrapper around xdg_menu that relies on /etc/update-menus.conf
+
This is a script wrapper around xdg_menu that relies on {{ic|/etc/update-menus.conf}}
  
You need to install package: archlinux-xdg-menu (xdg_menu)
+
You need to install package {{Pkg|archlinux-xdg-menu}} (xdg_menu)
  
/etc/update-menus.conf selects from a list of window managers for which the menu should be generated. Comments with # are allowed.
+
/{{ic|etc/update-menus.conf}} selects from a list of window managers for which the menu should be generated. Comments with # are allowed.
  
All generated menus placed in /var/cache/xdg-menu/. See wm-specific Examples section of this page to get more information.
+
All generated menus placed in {{ic|/var/cache/xdg-menu/}}. See wm-specific Examples section of this page to get more information.
  
 
== Examples ==
 
== Examples ==
Line 100: Line 115:
 
==== With xdg_menu ====
 
==== With xdg_menu ====
 
<pre>
 
<pre>
$ xdg_menu --format awesome >>~/.config/awesome/menu.lua
+
$ xdg_menu --format awesome --root-menu /etc/xdg/menus/arch-applications.menu >~/.config/awesome/archmenu.lua
 
</pre>
 
</pre>
 
Then edit your rc.lua as shown below
 
Then edit your rc.lua as shown below
Line 107: Line 122:
 
<pre>
 
<pre>
 
...
 
...
require("menu")
+
xdg_menu = require("archmenu")
 
...
 
...
  
Line 222: Line 237:
 
Generate menu with
 
Generate menu with
 
<pre>
 
<pre>
$ xdg_menu --format openbox3 --root-menu /etc/xdg/menus/arch-applications.menu >xdg-menu.xml
+
$ xdg_menu --format openbox3 --root-menu /etc/xdg/menus/arch-applications.menu > xdg-menu.xml
 
</pre>
 
</pre>
  
Line 232: Line 247:
  
 
into root-menu.
 
into root-menu.
 +
 +
==== As a pipe menu ====
 +
 +
Using xdg_open as a pipe menu gives you the added benefit of having a menu that automatically updates when you install new applications.
 +
 +
Add the following somewhere inside your menu.xml between your root menu tags
 +
<pre>
 +
<menu id="applications" label="Applications" execute="xdg_menu --format openbox3-pipe --root-menu /etc/xdg/menus/arch-applications.menu" />
 +
</pre>
 +
 +
A very basic example:
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
 +
<openbox_menu xmlns="http://openbox.org/3.4/menu">
 +
 +
<menu id="root-menu" label="Openbox 3">
 +
  <menu id="applications" label="Applications" execute="xdg_menu --format openbox3-pipe --root-menu /etc/xdg/menus/arch-applications.menu" />
 +
  <separator />
 +
  <item label="Log Out">
 +
    <action name="Exit">
 +
      <prompt>yes</prompt>
 +
    </action>
 +
  </item>
 +
</menu>
 +
 +
</openbox_menu>
 +
</pre>
  
 
==== With update-menus ====
 
==== With update-menus ====
Line 252: Line 295:
 
</pre>
 
</pre>
  
and add it into twmrc manualy.
+
and add it into twmrc manually. In the case of twm derivatives with m4 preprocessing such as vtwm or ctwm it can be included by adding
  
(I do not know how to include files into twmrc [[User:Sergej|sergej]] 10:50, 11 April 2007 (EDT))
+
<pre>
 +
sinclude(`/PATH/TO/my-twm-menu')
 +
</pre>
 +
 
 +
to *twmrc.
  
 
==== With update-menus ====
 
==== With update-menus ====
Line 264: Line 311:
 
* run update-menus as root
 
* run update-menus as root
 
* run twm -f /var/cache/xdg-menu/twm/twmrc
 
* run twm -f /var/cache/xdg-menu/twm/twmrc
 +
 +
(You will also want to add your other customizations to /etc/X11/twm/system.twmrc.)
  
 
=== WindowMaker ===
 
=== WindowMaker ===
Line 358: Line 407:
  
 
== See also ==
 
== See also ==
* [http://www.archlinux.org/packages/community/any/archlinux-xdg-menu/ archlinux-xdg-menu package in [community]]
+
* {{Pkg|archlinux-xdg-menu}}
 
* [http://standards.freedesktop.org/menu-spec/menu-spec-latest.html Free Desktop menu standard]
 
* [http://standards.freedesktop.org/menu-spec/menu-spec-latest.html Free Desktop menu standard]
 
* [[Sawfish|A workaround for sawfish]]
 
* [[Sawfish|A workaround for sawfish]]

Latest revision as of 11:39, 27 September 2016

xdg-menu generates menus for WMs using the Free Desktop menu standard. You can install archlinux-xdg-menu from the official repositories.

The following WMs are supported:

  • twm
  • ion3
  • WindowMaker
  • fvwm2
  • icewm
  • blackbox
  • fluxbox
  • openbox
  • awesome

KDE, Gnome, Xfce, Enlightenment are already XDG compatible.

Menu hierarchy

  • Applications
    • Accessibility
    • Accessories
    • Development
    • Education
    • Games
    • Graphics
    • Internet
    • Multimedia
    • Office
    • Other
    • Science
    • System

Configuration

Xdg_menu relies on three sets of information to generate menus: a root menu or in other words an XML menu template generally passed on the command line, information cached when it was last run, and a series of configuration files.

  • You can find some XML menu templates in /etc/xdg/menus.
  • If altering the code in xdg_menu to change layout, make sure you delete everything in ~/.xdg_menu_cache or you will spend hours trying to figure out why your changes to the perl script don't take.
  • You can find individual application configurations in /usr/share/applications

Other configuration file directories can be found under /usr/share. In most cases you will not need to touch these. However if you want to change how your menu is layed out you can alter the menu template for minor changes. Major changes require tweaking the actual xdg_menu perl script. If you find that applications do not appear or that they are called strange things, then you will need to look at the .desktop file in /usr/share/applications. Check this standards file .

Adding desktop entries from other directories

By default, the Xdg-menu will be populated with applications which install their desktop entries to /usr/share/applications. To add applications to the menu which install their desktop entry to a user folder such as ~/.local/share/applications, edit the /etc/xdg/menus/arch-applications.menu file and add an <AppDir> tag for the relevant directory, see below:

/etc/xdg/menus/arch-applications.menu
<Menu>

  <Name>Applications</Name>
  <Directory>Arch-Applications.directory</Directory>
  <DefaultAppDirs/>
  <AppDir>/home/username/.local/share/applications</AppDir>
  <DefaultDirectoryDirs/>
  <DefaultMergeDirs/>
  ...

Usage

xdg_menu

xdg_menu [--format <format>] [--desktop <desktop>] 
         [--charset <charset>] [--language <language>]  
	 [--root-menu <root-menu>] [--die-on-error]
	 [--fullmenu] [--help]
		 
	format - output format
	         possible formats: twm, WindowMaker, fvwm2, icewm, ion3
	                           blackbox, fluxbox, openbox, 
				   xfce4, openbox3, openbox3-pipe, awesome
				   readable
		 default: WindowMaker
		
 	fullmenu  - output a full menu and not only a submenu

	desktop - desktop name for NotShowIn and OnlyShowIn
		 default: the same as format
			 
	charset - output charset
		 default: <locale>
			 
	language - output language
		 default: <locale>
			 
	root-menu - location of root menu file
		 default: /opt/gnome/etc/xdg/menus/applications.menu
			 
	die-on-error - abort execution on any error, 
		 default: try to continue

	verbose - print debugging information
		 
	help - print this text

update-menus

update-menus updates WMs menus from XDG stuff and can do it automaticaly using config.

This is a script wrapper around xdg_menu that relies on /etc/update-menus.conf

You need to install package archlinux-xdg-menu (xdg_menu)

/etc/update-menus.conf selects from a list of window managers for which the menu should be generated. Comments with # are allowed.

All generated menus placed in /var/cache/xdg-menu/. See wm-specific Examples section of this page to get more information.

Examples

Awesome

With xdg_menu

$ xdg_menu --format awesome --root-menu /etc/xdg/menus/arch-applications.menu >~/.config/awesome/archmenu.lua

Then edit your rc.lua as shown below

  • Add a require statment for your new menu.lua file
  • Add an entry to your awful.menu object for your new menu which calls xdgmenu
...
xdg_menu = require("archmenu")
...

...
mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
                                    { "Applications", xdgmenu },
                                    { "open terminal", terminal }
                                  }
                        })
...

IceWM

With xdg_menu

$ xdg_menu --format icewm --fullmenu --root-menu /etc/xdg/menus/arch-applications.menu >>~/.icewm/programs

With update-menus

  • Uncomment icewm in /etc/update-menus.conf
  • run update-menus as root
  • make symlink to /var/cache/xdg-menu/icewm/programs in ~/.icewm/programs

Ion3

With xdg_menu

$ xdg_menu --format ion3  --root-menu /etc/xdg/menus/arch-applications.menu >~/.ion3/default-session--0/_xdg-menu.lua

After that, change your cfg_menus.lua to include _xdg-menu.lua file and add menu into mainmenu. For example:

...

dopath("_xdg-menu")

-- Main menu
defmenu("mainmenu", {
    submenu("XDG Menu",         "<NAME-OF-FIRST-MENU-IN-_xdg-menu.lua-FILE>"),
    submenu("Programs",         "appmenu"),
    menuentry("Lock screen",    "ioncore.exec_on(_, 'xlock')"),
    menuentry("Help",           "mod_query.query_man(_)"),
    menuentry("About Ion",      "mod_query.show_about_ion(_)"),
    submenu("Styles",           "stylemenu"),
    submenu("Session",          "sessionmenu"),
})

...

With update-menus

  • Uncomment ion3 in /etc/update-menus.conf
  • run update-menus as root
  • change your cfg_menus.lua to include xdg-menu.lua file and add menu into mainmenu.

For example:

...

dopath("/var/cache/xdg-menu/ion3/xdg-menu.lua")

-- Main menu
defmenu("mainmenu", {
    submenu("XDG Menu",         "<NAME-OF-FIRST-MENU-IN-xdg-menu.lua-FILE>"),
    submenu("Programs",         "appmenu"),
    menuentry("Lock screen",    "ioncore.exec_on(_, 'xlock')"),
    menuentry("Help",           "mod_query.query_man(_)"),
    menuentry("About Ion",      "mod_query.show_about_ion(_)"),
    submenu("Styles",           "stylemenu"),
    submenu("Session",          "sessionmenu"),
})

...

FluxBox

With xdg_menu

$ xdg_menu --format fluxbox  --root-menu /etc/xdg/menus/arch-applications.menu >~/.fluxbox/my-menu

Change your menu file to include generated menu.

For example add line:

      [include] (my-menu)

With update-menus

  • Uncomment fluxbox in /etc/update-menus.conf
  • run update-menus as root
  • change your menu file to include generated menu.

For example add line:

      [include] (/var/cache/xdg-menu/fluxbox/boxrc)

OpenBox

With xdg_menu

Generate menu with

$ xdg_menu --format openbox3 --root-menu /etc/xdg/menus/arch-applications.menu > xdg-menu.xml

and manually add it into your menu.xml. For example, put xdg-menu.xml into menu.xml and add:

<menu id="Applications" />

into root-menu.

As a pipe menu

Using xdg_open as a pipe menu gives you the added benefit of having a menu that automatically updates when you install new applications.

Add the following somewhere inside your menu.xml between your root menu tags

<menu id="applications" label="Applications" execute="xdg_menu --format openbox3-pipe --root-menu /etc/xdg/menus/arch-applications.menu" />

A very basic example:

<?xml version="1.0" encoding="UTF-8"?>

<openbox_menu xmlns="http://openbox.org/3.4/menu">

<menu id="root-menu" label="Openbox 3">
  <menu id="applications" label="Applications" execute="xdg_menu --format openbox3-pipe --root-menu /etc/xdg/menus/arch-applications.menu" />
  <separator />
  <item label="Log Out">
    <action name="Exit">
      <prompt>yes</prompt>
    </action>
  </item>
</menu>

</openbox_menu>

With update-menus

  • Uncomment openbox in /etc/update-menus.conf
  • run update-menus as root
  • change your menu.xml file to include generated menu.

For example, add following to root-menu:

<menu id="xdg-menu" label="XDG Menu" execute="cat /var/cache/xdg-menu/openbox/menu.xml"/>

Twm

With xdg_menu

Use

$ xdg_menu --format twm --root-menu /etc/xdg/menus/arch-applications.menu >my-twm-menu

and add it into twmrc manually. In the case of twm derivatives with m4 preprocessing such as vtwm or ctwm it can be included by adding

sinclude(`/PATH/TO/my-twm-menu')

to *twmrc.

With update-menus

  • Uncomment twm in /etc/update-menus.conf
  • Add into /etc/X11/twm/system.twmrc file applications menu (add following line:
 "apps"          f.menu "Applications"

into defops menu)

  • run update-menus as root
  • run twm -f /var/cache/xdg-menu/twm/twmrc

(You will also want to add your other customizations to /etc/X11/twm/system.twmrc.)

WindowMaker

With xdg_menu

Use

$ xdg_menu --format WindowMaker --root-menu /etc/xdg/menus/arch-applications.menu >my-wm-menu

and add

#include "my-wm-menu"

into your WindowMaker menu file.

You can also use the WPrefs "Application Menu Definitions", and add the xdg command as a parameter in a "Generated Submenu" object.

With update-menus

  • Uncomment WindowMaker in /etc/update-menus.conf
  • run update-menus as root
  • add
#include "/var/cache/xdg-menu/WindowMaker/wmrc"

into your menu file.

Fvwm2

With xdg_menu

Generate menu

$ xdg_menu --format fvwm2 --root-menu /etc/xdg/menus/arch-applications.menu >fvwm2-menu

and add menu into root menu

read fvwm2-menu

AddToMenu MenuFvwmRoot  "Root Menu"             Title
+                       "&0. XDG Menu"          Popup xdg_menu

With update-menus

  • Uncomment fvwm2 in /etc/update-menus.conf
  • run update-menus as root
  • change your .fvwm2rc file to include generated menu. For example:
AddToMenu MenuFvwmRoot  "Root Menu"             Title
+                       "&0. XDG Menu"          Popup xdg_menu
read /var/cache/xdg-menu/fvwm2/fvwm2rc

BlackBox

With xdg_menu

$ xdg_menu --format blackbox  --root-menu /etc/xdg/menus/arch-applications.menu >my-menu

Change your menu file to include generated menu.

For example add line:

[include] (my-menu)

With update-menus

  • Uncomment blackbox in /etc/update-menus.conf
  • run update-menus as root
  • change your menu file to include generated menu.

For example add line:

[include] (/var/cache/xdg-menu/blackbox/boxrc)

See also