![alt tag](https://gitlab.version.fz-juelich.de/vis/xdg_profiles/raw/master/screenshot_xdg_profile_vis.png)

# XDG Desktop Profiles

The support of VNC remote graphical desktops on JURECA enables us to presents the JSC to the HPC-Users in a fresh and modern way.
But a graphical desktop is of course not limited to eye-candy design alone.

A graphical desktop can increase productivity of each HPC-user as the workflows become more complex and change more often.
It also helps new users to shorten the time to debug, run and post-process their codes (e.g. debugging, performance and visualization tools are more easy to start use).
But different user groups and various research topics make sense for multiple desktop configurations.

The solution are XDG Desktop Profiles (https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)


## What is an XDG Desktop Profile?

A XDG desktop profile is a set of desktop configurations, most notable:
- background image
- desktop icons
- applications menu ("Start Menu")
- desktop widgets (information embedded into the background image)
- autostart
- application configurations

#### ${XDG_CONFIG_*}
All of these settings are stored in files located in *${XDG_CONFIG_HOME}* for each user.
Global settings are stored in *${XDG_CONFIG_DIRS}*.
The default of *${XDG_CONFIG_HOME}* is *${HOME}/.config/* and the default of global settings is */etc/xdg/*.

New configurations and modifications made by the user are stored in *${XDG_CONFIG_HOME}*.
These configurations overwrite all settings located in *${XDG_CONFIG_DIRS}*.

#### ${XDG_DATA_*}
All XDG data, which is independent of a certain configuration, is stored in *${XDG_DATA_HOME}* for each user or in *${XDG_DATA_DIRS}* system-wide.
This can be background images .desktop-files for desktop icons, menus or autostart files.
The default for *${XDG_DATA_HOME}* is *${HOME}/.local* and for *${XDG_DATA_DIRS}* it is */usr/local/share:/usr/share*.

#### /etc/xdg/xdg_profiles/\<profile\>/
Each XDG desktop profile is stored in its own XDG_CONFIG-directory (*/etc/xdg/xdg_profiles/\<profile\>/*) and inherit configurations from the desktop profiles 'default' and the linux-distribution-defaults in */etc/xdg*.
Hence, a new XDG desktop profile might consist only of some additional desktop icons, a different background image or an new sub-menu for the application menus added on top of the default profile.


## How are XDG Desktop Profiles chosen?

The XDG Desktop Profile is chosen with *${XDG_PROFILE}* just before the VNC server is started.
```shell
export XDG_PROFILE=vis
vncserver -fg -geometry 1920x1080
```
The VNC server calls *${HOME}/.vnc/xstartup* (use *dot.vnc/xstartup* from this repository),
which must call **xdg_profile.sh** currently located in *etc/xdg/* of this repository.

If the directory *etc/xdg/xdg_profiles/${XDG_PROFILE}* exists, xdg_profile.sh sets the *${XDG_CONFIG_\*}* and *${XDG_DATA_\*}* variables. .

Example: starting a VNC-server-job with an the visualization XDG desktop profile on a visualization the visualization partition of JURECA:
```shell
salloc -N 1 -p vis --gres=mem512,gpu:1 --start-xserver --time=1:00:00
srun -n 1 --cpu_bind=none --gres=gpu:1 bash -c 'export XDG_PROFILE=vis; vncserver -fg -geometry 1920x1080'
```


## XFCE4 XDG configurations

XDG Base Directory Specification are supported by most of the popular desktop systems found on Linux (GNOME, KDE, XFCE etc.). On JURECA we use XFCE4 as a light weighted desktop system.

XFCE4 specific configurations are stored in *${XDF_CONFIG_\*}/xfce4/* and
XFCE4 specific data is stored in *${XDF_DATA_\*}/xfce4/*. Examples are:

- desktop settings
  - desktop settings file (including background image)
    - ${XDF_CONFIG_\*}/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml
  - desktop menu description file:
    - ${XDG_CONFIG_\*}/xfce4/desktop/menu.xml
  - default location of all desktop backgrounds:
    - ${XDF_DATA_\*}/xfce4/backdrops/*

- panel settings
  - panel settings file
    - ${XDG_CONFIG_\*}/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml
  - panel widget description files:
    - ${XDG_CONFIG_\*}/xfce4/panel/

#### Background Image

The background image is set in *${XDF_CONFIG_\*}/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml*.
The first XDF_CONFIG-directory, which includes this file sets the background image.

The path must be an absolute path.
It is not processed by bash and must not include any system variables.

Background images of desktop profiles should be located in *${XDF_DATA_\*}/xfce4/backdrops/* to be found by XFCE4 on default.

XFCE4 can loop through background images.
Therefore multiple images must be listed in */etc/xdg/xdg_profiles/\<profile\>/xfce4/desktop/backdrop.list*.
backdrop-cycle-enable and backdrop-cycle-timer must be set in */etc/xdg/xdg_profiles/\<profile\>/xfce4/xfconf/xfce-perchannel.xml/xfce4-desktop.xml*.

#### Desktop Icons

In XFCE4 icons are positioned with row/column coordinates.
The position is stored in *${XDF_CONFIG_\*}/xfce4/desktop/icons.screen?-<resolution-identifier>.rc*.
If the size of each cell is changed, the coordinates remain the same but the grid gets enlarged.

XFCE4 will rearrange all icons on the desktop, if the screen resolution is smaller than the required resolution needed to fit the max. row or max. column.
Hence, icons be placed in the top left area of the desktop and must fit on a min. resolution of 1024x768 in each desktop profile.

#### Application Menu

##### Customize Menu Structure
The applications menu is generated from the file *etc/xdg/xdg_profiles/default/config/menus/xfce-applications.menu*.
It merges additional menus from *${XDG_CONFIG_\*}/menus/application-merged/*.

Sub-menu of XDG desktop profiles are located in *etc/xdg/xdg_profiles/\<profile\>/config/menus/application-merged/.
Profile-specific .directory-files must be placed in *etc/xdg/xdg_profiles/\<profile\>/data/desktop-directories/*.
Additional information can be found here *https://wiki.xfce.org/howto/customize-menu*.

Sub-menus of general profiles (like 'Visualization', 'Performance Analysis', etc.) can be placed in the profile 'default', too, to be visible in any profile.

##### Customize Menu Entries
Any menu entry belongs to a corresponding .desktop-file in *${XDG_DATA_DIRS}/applications*.

The category name (defined by xfce-applications.menu and its .directory-files) describes in which sub-menu it will be placed.
Example: vis.directory defines the category "Visualization".
Adding "Category=Visualization" to a .desktop-file will place it in the sub-menu "Visualization".

##### Change Application Menu Icon
The application menu icon is set in *${XDF_CONFIG_\*}/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml*.

By default it is set in the default profile in *etc/xdg/xdg_profiles/default/config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml*
to the FZJ logo located in *etc/xdg/xdg_profiles/default/data/pixmaps/fzj-logo_64x64.png*.

#### Info-Terminal

An info terminal can be part of a profile to present text information to the user.
It is located in *etc/xdg/xdg_profiles/\<profile\>/config/infoterm-\<profile\>*.

It is started via the desktop-file */etc/xdg/xdg_profiles/\<profile\>/config/autostart/infoterm-\<profile\>.desktop* on every start of XFCE4 with the desktop profile \<profile\>.
In all directories of XDG_CONFIG_DIRS the script infoterm-\<profile\>.sh is searched and (if found) executed:
```shell
IFS=:
for p in ${XDG_CONFIG_DIRS}; do
  if [ -e ${p}/infoterm-\<profile\>/infoterm-\<profile\>.sh ]; then
    ${p}/infoterm-\<profile\>/infoterm-\<profile\>.sh
    break
  fi
done
```
infoterm-\<profile\>.sh must be unique and only part of a single desktop profiles - do not use the same name in multiple desktop profiles.

The configuration of the info terminal is done partly in *infoterm-\<profile\>.sh* and partly by setting the application specific XDG_CONFIG_HOME to *etc/xdg/xdg_profiles/\<profile\>/config/infoterm-\<profile\>*.
This is for settings, which cannot be done via command line parameters like transparency and are only stored in configuration files.


## How to generate a new profile

#### Create the XDG desktop profile
1. Rename your ${HOME}/.config to start with no user-specific configurations.
2. Start VNC with the default profile:
```shell
export XDG_PROFILE=default
vncserver -fg -geometry 1920x1080
```
3. Make your changes (background, icons, menu entries)
4. logout

#### Store the XDG desktop profile
1. Copy *${HOME}/.config/xdg_profiles/default* to *etc/xdg/xdg_profiles/\<new-profile-name\>/config/*
2. Replace absolute paths pointing to locations inside your ${HOME} (use setup.sh).
3. Copy .desktop-files generated in ${HOME}/Desktop to *etc/xdg/xdg_profiles/\<new-profile-name\>/data/*.


## IMPORTANT NOTICE:

1. Absolute paths are present in the configuration files of this repository. They have to be changed before use:
  - **call ./setup.sh to change the paths**

2. copy or link dot.vnc/xstartup to your ~/.vnc directory