为什么图像文件没有出现在登录屏幕中但却出现在解锁屏幕中?

为什么图像文件没有出现在登录屏幕中但却出现在解锁屏幕中?

我有一个自定义的“mytheme.css”,它曾经能够使用 url 命令显示登录屏幕和解锁屏幕壁纸或任何其他图标。它们使用的路径是相对于“mytheme”目录指定的,即/usr/share/gnome-shell/theme/mytheme。例如,

/*login & unlock screens wallpaper*/
#lockDialogGroup {
  background: #2c001e url("assets/lockDialogGroup.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

/* switch colors */
.toggle-switch-us:checked {
  background-image: url("assets/toggle-on.svg");
}

然而最近不知何故url 命令的语法不适用于登录屏幕,但适用于 Ubuntu 18.04 中的解锁屏幕。这意味着我可以在解锁屏幕上看到我的壁纸,但在登录屏幕上看不到。

为了解决这个问题,我目前必须使用file命令。但是,这样做需要说明壁纸的完整路径,而这相当长。例如,上面的 url 命令必须修改为:

   background: #2c001e url(file:///usr/share/gnome-shell/theme/mytheme/assets/lockDialogGroup.jpg);

background-image: url(file:///usr/share/gnome-shell/theme/mytheme/assets/toggle-on.svg);

我不明白的是根据 css,假设我的主题的 css 文件完整路径是/usr/share/gnome-shell/theme/mytheme/mytheme.css,则引用目录应该是/usr/share/gnome-shell/theme/mytheme/,如果壁纸的完整路径是/usr/share/gnome-shell/theme/mytheme/assets/lockDialogGroup.jpg,那么我只需要声明一个相对路径即可显示壁纸:

  background: #2c001e url("assets/lockDialogGroup.jpg");

奇怪的是,此命令适用于解锁屏幕,但对登录屏幕无效。请记住,我之前已设置/usr/share/gnome-shell/modes/ubuntu.json为显示:

{
    "parentMode": "user",
    "stylesheetName": "mytheme/mytheme.css",
    "enabledExtensions": [
        "[email protected]",
        "[email protected]"
    ]
}

那么,到底发生了什么呢?

答案1

解决方法尝试并尝试

操作系统:Ubuntu 18.04

/usr/share/gnome-shell/theme/ubuntu.css在默认的 Ubuntu 18.04 安装中,如果您观察为 GDM 和锁屏配置的文件...

文件的某些部分ubuntu.css

/* switch colors */
.toggle-switch-us:checked {
  background-image: url("ubuntu-toggle-on-us.svg");
}
.toggle-switch-intl:checked {
  background-image: url("ubuntu-toggle-on-intl.svg");
}

url 部分表示.. .svg 文件路径相对于/usr/share/gnome-shell/theme/

因此,当您有/usr/share/gnome-shell/theme/mytheme/mytheme.css并且图像路径url("assets/1.jpg")简单时,将文件夹资产复制到/usr/share/gnome-shell/theme/

这意味着,锁屏将url("assets/1.jpg")考虑/usr/share/gnome-shell/theme/mytheme/assets/1.jpg

并且 GDM 将url("assets/1.jpg")考虑/usr/share/gnome-shell/theme/assets/1.jpg

pratap@i7-4770:~$ sudo update-alternatives --config gdm3.css
[sudo] password for pratap: 
There are 2 choices for the alternative gdm3.css (providing /usr/share/gnome-shell/theme/gdm3.css).

  Selection    Path                                              Priority   Status
------------------------------------------------------------
* 0            /usr/share/gnome-shell/theme/MyTheme/MyTheme.css   100       auto mode
  1            /usr/share/gnome-shell/theme/MyTheme/MyTheme.css   100       manual mode
  2            /usr/share/gnome-shell/theme/ubuntu.css            10        manual mode

Press <enter> to keep the current choice[*], or type selection number: 
pratap@i7-4770:~$ 

GDM 屏幕 在此处输入图片描述

锁定屏幕 在此处输入图片描述

在此处输入图片描述

在此处输入图片描述


或者,您可以创建如下命令assets的符号链接,而不是复制粘贴文件夹。/usr/share/gnome-shell/theme/mytheme/assets

sudo ln -s /usr/share/gnome-shell/theme/mytheme/assets /usr/share/gnome-shell/theme/

在此处输入图片描述


或者,最好的方法是首先创建到mytheme目录的符号链接,如下面的命令

sudo ln -s /usr/share/gnome-shell/theme/mytheme /usr/share/gnome-shell/

然后按照下面的命令安装更新替代方案

sudo update-alternatives --install /usr/share/gnome-shell/theme/gdm3.css gdm3.css /usr/share/gnome-shell/mytheme/mytheme.css 100

例子:

pratap@i7-4770:~$ sudo update-alternatives --config gdm3.css 
[sudo] password for pratap: 
There are 3 choices for the alternative gdm3.css (providing /usr/share/gnome-shell/theme/gdm3.css).

  Selection    Path                                              Priority   Status
------------------------------------------------------------
* 0            /usr/share/gnome-shell/MyTheme/MyTheme.css         100       auto mode
  1            /usr/share/gnome-shell/MyTheme/MyTheme.css         100       manual mode
  2            /usr/share/gnome-shell/theme/MyTheme/MyTheme.css   100       manual mode
  3            /usr/share/gnome-shell/theme/ubuntu.css            10        manual mode

Press <enter> to keep the current choice[*], or type selection number: 

在此处输入图片描述

相关内容