Tip: background image for desktop

Briefly discussed on the last zoom call; since I suspect many provide desktop session on login nodes as well as ondemand desktops on compute nodes; i recommend configuring them to show a default desktop background image that highlights the nodename and if it’s a login node.

I also found that now many desktop users don’t see our MOTD either so I decided to write a small pythonscript that generates an SVG with the info.

I roll this out with ansible;

#!/usr/bin/env python3
import socket, os
import argparse


parser = argparse.ArgumentParser(description='Write nodeinfo as SVG image.')
parser.add_argument('-o', dest='output', help='output file', required=True)

args = parser.parse_args()

header = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"
     xml:lang="en" width="280mm" height="200mm">
    <title>nodeinfo</title>
    <defs>
      <filter id="shadow" x="0" y="0" width="200%" height="200%">
        <feOffset result="shadow" in="SourceAlpha" dx="0.5mm" dy="0.5mm"/>
        <feColorMatrix in="shadow" result="softshadow" type="matrix"
          values="0 0 0 0  0
                  0 0 0 0  0 
                  0 0 0 0  0 
                  0 0 0 .5 0"/>
        <feBlend in="SourceGraphic" in2="softshadow" mode="normal" />
      </filter>
    </defs>
    <style type="text/css">
        svg {
            font-family: monospace;
            fill: gray;
            opacity: 0.80;
        }
        .hostname {
            font-size: 12mm;
        }
        .message {
            font-style: italic;
            font-size: 6mm;
        }
        .motd {
            font-size: 0.5cm;
        }
    </style>
"""

footer = "</svg>"

charwidth = 37/12  # width of character in MOTD section in mm. Found experimentally.

with open(args.output, 'w') as fout:

    fout.write(header)
    fout.write('<text filter="url(#shadow)">\n')
    fout.write('<tspan class="hostname" x="100mm" y="20mm">{0}</tspan>\n'.format(socket.gethostname()))
{% if slurm_profile == 'login' %}
    fout.write('<tspan class="message" x="5mm" dy="10mm">This is a shared login node.</tspan>\n')
    fout.write('<tspan class="message" x="5mm" dy="8mm">Use with care and submit jobs to the queue.</tspan>\n')
{% endif %}
    fout.write('<tspan class="message" x="5mm" dy="8mm">For support, see https://www.c3se.chalmers.se/support</tspan>\n')
    fout.write('</text>\n')

    if os.path.exists('/etc/motd.d'):
        fout.write('<text y="50mm" class="motd" filter="url(#shadow)">\n')
        for motdfile in os.listdir('/etc/motd.d'):
            with open('/etc/motd.d/' + motdfile) as f:
                for line in f:
                    sline = line.lstrip(' ')
                    pad = len(line) - len(sline)
                    fout.write('<tspan x="5mm" dy="7mm" dx="{0:.0f}mm">{1}</tspan>\n'.format(pad*charwidth, sline.strip()))
        fout.write('</text>\n')
    fout.write(footer)

Fortunately XFCE4 auto-updates desktop background when the file is modified, so i just run that as a timed service

I set the default background to be centered via /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml

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

<channel name="xfce4-desktop" version="1.0">
  <property name="backdrop" type="empty">
    <property name="screen0" type="empty">
      <property name="monitorVNC-0" type="empty">
        <property name="workspace0" type="empty">
          <property name="color-style" type="int" value="0"/>
          <property name="image-style" type="int" value="1"/>
          <property name="last-image" type="string" value="/usr/share/backgrounds/nodeinfo.svg"/>
        </property>
        <property name="workspace1" type="empty">
          <property name="color-style" type="int" value="0"/>
          <property name="image-style" type="int" value="5"/>
          <property name="last-image" type="string" value="/usr/share/backgrounds/images/default.png"/>
        </property>
        <property name="workspace2" type="empty">
          <property name="color-style" type="int" value="0"/>
          <property name="image-style" type="int" value="5"/>
          <property name="last-image" type="string" value="/usr/share/backgrounds/images/default.png"/>
        </property>
        <property name="workspace3" type="empty">
          <property name="color-style" type="int" value="0"/>
          <property name="image-style" type="int" value="5"/>
          <property name="last-image" type="string" value="/usr/share/backgrounds/images/default.png"/>
        </property>
      </property>
    </property>
  </property>
</channel>

All the measurements were eyeballed to look roughly right as most desktop sizes :smile:

Looks something like this

1 Like