Human Readable  

 

     
   
     

Modifying the KDE K-Menu Globally

© Copyright Darrell Anderson.

(Updated Autumn 2008)

Many people dislike the stock KDE menu structure. A more likeable global menu structure is possible. Additionally, users can personalize the new modified global menu too. This approach provides flexibility for administrators and users.

KDE provides no straightforward method to modify the default K-Menu in a global manner such that all users will see the new menu. The KDE menu editor tool is user-centric. All menu modifications are stored in the respective user’s home directory in $HOME/.config/menus. The name of the menu file will be applications-kmenuedit.menu.

Any related name or comment changes are stored in respective *.desktop files located in $HOME/.local/share/applications. The trick is moving those files to a location affecting all users.

One work-around to modifying the menu globally is to perform those changes — as normal user is fine — and then as root user move the resulting applications-kmenuedit.menu file from $HOME/.config/menus to an appropriate xdg/menus directory. For Slackware there are three locations defined in the $XDG_CONFIG_DIRS environment variable:

/etc/xdg
/etc/kde/xdg
/etc/xfce/xdg

The second directory is where the global KDE menu structure is stored in Slackware.

Within each xdg directory will be a menus directory. For KDE there will be a submenu named applications-merged. This is the location to move the newly created menu directory. By default and according to the xdg standard, this is where non-stock menu additions should be stored.

Notice in /etc/kde/xdg/menus/applications.menu, at the bottom of the file, is a MergeFile directive including files with the name of applications-kmenuedit.menu. Moving this file from the user’s $HOME directory to /etc/kde/xdg/menus will programmatically result in the file being merged with the stock KDE menus. The file does not have to be in the applications-merged subdirectory if named applications-kmenuedit.menu.

That is the intent but carries a caveat. After modifying the menus globally for all users, when individual users begin to personalize their own menu, the resulting file will carry the same name as previously described. In that event, the user’s applications-kmenuedit.menu will override the new global menu of the same name. That user will not see the global changes. To avoid that problem store the new file in /etc/kde/xdg/menus/applications-merged and change the name of the file from applications-kmenuedit.menu to something like applications-local.menu. The two files then will not conflict.

Further, when creating this new menu structure for all users, be sure to do so from a user account that has not previously modified the menu structure. That is, begin with a clean slate. Otherwise all of the user’s menu modifications will become global when the files are moved.

There remains the task of moving the respective *.desktop files. These must be moved to known standard locations:

/usr/share/applications
/usr/local/share/applications

The /usr/local location is the preferred place to install localized modifications.

A third location for these files — and for the resulting new menu file too, is available by using the $KDEDIRS environment variable (notice the trailing “s”). If this variable is used and defines a second $KDEDIR location, then these menu and desktop files can be stored in that file path.

On my box the standard $KDEDIR environment variable is defined as /usr. I have $KDEDIRLOCAL defined as /usr/local/kde-mods. I then have $KDEDIRS defined as $KDEDIRLOCAL:$KDEDIR or /usr/local/kde-mods:/usr.

This $KDEDIRS variable instructs KDE to use both directories but my $KDEDIRLOCAL pointing to /usr/local takes precedence over the stock files stored in /usr. This second location works well for me because any time I update KDE I do not have to worry about losing my local configurations.

I modified my $XDG_CONFIG_DIRS environment variable to:

/etc/xdg
/etc/kde/xdg
/usr/local/kde-mods/etc/xdg
/etc/xfce/xdg

I have my new global menu file stored in $KDEDIRLOCAL/etc/xdg/menus/applications-merged.

I have my modified *.desktop files located in $KDEDIRLOCAL/share/applications.

Another caveat to be watch. The KDE menu editor tool creates the respective *.desktop files with 600 (rw-------) file permissions. When these files are moved to a global location, they will retain those permissions. Be sure to modify the permissions of all affected files to 644 (rw-r--r--). Otherwise only root will be able to see the changes.

Finis.

Table of Contents