更改 GDM 背景

更改 GDM 背景

我正在使用安装了 GDM 和 Gnome 的 Archlinux (Antergos)。有什么方法可以更改 GDM 背景吗?

通过在 Gnome 设置中设置锁定屏幕背景,它只会在计算机锁定时更改 GDM 背景,而不是在登录时更改。

答案1

我发现此解决方案在这里写了脚本使其自动化。哇!

创建 xml 文件来自这个粘贴~/chgdm-bg-tmp/theme/gnome-shell-theme.gresource.xml如果出现错误则调用Could not find file gnome-shell-theme.gresource.xml

编辑:当我从 gnome-shell 3.16 升级到 3.26 时,这个问题就出现了。原因是有些资源不再使用,因此 glib-compile-resources 命令失败。如果您遇到错误,我建议删除以下行:<file>more-results.svg</file>然后它应该可以正常编译。

#!/bin/bash

if [ -z "$1" ]; then
  echo "Usage: ./chgdm-bg <path/to/picture.png> [y/n]"
  exit 1
fi

echo MAKE SURE YOUR PICTURE IS THE SAME RESOLUTION AS YOUR SCREEN.
echo If you dont you will likely regret it.
sleep 3

if [ ! -f $1 ]; then
  echo Error: could not find file $1
  exit 1
fi

PIC=$1
WORKDIR=${HOME}/chgdm-bg-tmp
DATE=$(date +"%Y-%m-%d_%T")

if [ ! -d $WORKDIR ]; then
  mkdir -p $WORKDIR/theme
fi

cd "${WORKDIR}/theme"
mkdir -p backups

IFS='/' read -r -a array <<< "$PIC"
cp $PIC .
PIC=${array[-1]}
echo "Target picture: ${PIC}"
chmod 777 $PIC

SHARE=/usr/share/gnome-shell/
GRESOURCE=gnome-shell-theme.gresource
CSS=gnome-shell.css
XMLRES=gnome-shell-theme.gresource.xml

if [ -f ${SHARE}${GRESOURCE} ]; then
  echo Backing up ${SHARE}${GRESOURCE}...
  cp ${SHARE}${GRESOURCE} "backups/${GRESOURCE}.bak.${DATE}"
  cp ${SHARE}${GRESOURCE} $GRESOURCE
  printf "Unpacking binary resource..."
  for r in `gresource list $GRESOURCE`; do
    printf "."
    gresource extract $GRESOURCE $r >$WORKDIR/${r#\/org\/gnome\/shell/}
  done
  echo
  WORKDIR="${WORKDIR}/theme/"


  if [ -f ${XMLRES} ]; then
    echo Backing up ${XMLRES}...
    cp "${XMLRES}" "backups/${XMLRES}.bak.${DATE}"
    if [ -f "tmp" ]; then
      rm -f tmp
    fi
    touch tmp
    awk -v var="$PIC" '/gresource prefix="\/org\/gnome\/shell\/theme">/ { print; printf "    <file>"; printf var; print "<\/file>"; next }1' $XMLRES > tmp && mv tmp $XMLRES
    #sed -n -i "/\ \ \ \ <file>$PIC<\/file>/d" $XMLRES
    #sed -n -i "/gresource prefix=\"\/org\/gnome\/shell\/theme\">/a \ \ \ \ <file>$PIC<\/file>" $XMLRES
  else
    echo Error: could not find file ${XMLRES}
    exit 1
  fi

  if [ -f $CSS ]; then
    echo Backing up $CSS...
    cp $CSS "backups/${CSS}.bak.${DATE}"
    sed -i 's/#lockDialogGroup/#lockDialogGroup-old/' $CSS
    printf "#lockDialogGroup {\n    background: #2e3436 url(${PIC});\n    background-repeat: no-repeat;\n    background-size: cover; }\n" >> $CSS
  else
    echo Error: could not find file $CSS
    exit 1
  fi

  echo Compiling binary resources...
  glib-compile-resources $XMLRES
  echo Copying binary resources over to ${SHARE}...
  sudo cp $GRESOURCE "${SHARE}${GRESOURCE}"
  sudo cp $CSS "${SHARE}${CSS}"

  if [ -z $2 ]; then
    echo "Restart now? (y/n)"
    read ans
  fi

  if [ "$2" = "y" ] || [ "$ans" = "y" ]; then
    echo Restarting...
    for i in {1..5}; do
      echo $((6-i))
      sleep 1
    done
    #/usr/bin/gnome-session-quit --no-prompt
    #sudo pkill -u $USER
    sudo shutdown -r now
  else
    echo Restart to load your changes.
  fi
else
  echo Error: could not find file ${SHARE}${GRESOURCE}
  exit 1
fi

答案2

GDM 使用 gresource,这意味着我们不能直接改变背景,我们必须重建 .geresource 文件。

最快的方法是使用一个名为阿奇博尔德

安装方法:

curl -L -O http://archibold.io/sh/archibold
chmod +x archibold
sudo mv archibold /usr/bin/

使用方法:

sudo archibold login-background background.png

只需将 background.png 替换为新背景的路径即可。然后您需要重新启动 GDM(例如通过重新启动)。

相关内容