(我知道我可以使用Ctrl + Super + D的键盘快捷键来显示桌面,并且我可以安装一个扩展来在顶部栏中添加一个“显示桌面”按钮,但我特别想要一个在dash中的按钮。)
wmctrl
在X11和Wayland窗口管理器中都可以使用,并且不需要sudo
权限。 - Gabriel Stapleswmctrl
解决方案,无论是在X11还是Wayland窗口管理器中,它都能很好地显示和隐藏窗口/桌面! - Gabriel Staplesstatus="$(wmctrl -m | grep "showing the desktop" | grep -Eo "ON|OFF")"
。 - Gabriel Staples这对我来说是最合适的。
在Ubuntu 14.04、16.04、18.04、20.04、22.04等版本中测试通过,并且需要使用X11窗口管理器,而不是Wayland。
在Ubuntu 20.04、22.04等版本中使用X11窗口管理器的方法:
现在,以下操作将起作用:
信用:以下内容不是我想出来的,而是 Ubuntu 的天才和博主 Ji m 在这里提出的:http://ubuntuhandbook.org/index.php/2018/10/add-show-desktop-button-ubuntu-18-10-18-04/。我直接借用了他的材料(其中很多是直接引用的)。打开终端(Ctrl + Alt + T)并安装xdotool:
sudo apt install xdotool
然后通过以下命令创建显示桌面的快捷方式图标并进行编辑:
gedit ~/.local/share/applications/show-desktop.desktop
当文件打开时,粘贴以下内容并保存。
[Desktop Entry]
Type=Application
Name=Show Desktop
Icon=desktop
Exec=xdotool key --clearmodifiers Super+d
最后在应用程序菜单中搜索“show desktop”,然后右键点击并选择“添加到收藏夹”:
就是这样。尽情享受吧!
这是我桌面上显示的效果:
点击您的“开始菜单”图标(九点图标),然后输入“显示桌面”。等待几秒钟,搜索结果会弹出,然后点击并安装一个Gnome Shell扩展程序。(请注意,这些搜索结果仅来自Ubuntu软件中心)。
关于Gnome Shell扩展的更多信息,请查看我在这里的其他答案:https://askubuntu.com/a/1089033/327339。
点击"安装"按钮,这是它在我的桌面上的样子:
这是另一个选项[曾经是我个人最喜欢的,但后来我又切换回选项 1,因为它似乎工作得最顺畅且最一致]:
这是安装后的样子:@AndAC有一个很好的答案。我已经给它点赞了。我还有这里的一个较旧的回答。
今天,我在我的eRCaGuy_dotfiles存储库中添加了我自己的show_desktop.sh
脚本和show-desktop.desktop
文件,并且想要展示如何使用它们。所以,对于我设置的任何新计算机(我经常这样做),这是我现在在计算机上设置"显示桌面"图标的方法:
在Ubuntu 22.04.2上,在X11和Wayland窗口管理器中进行了测试。
# 1. Install dependencies
sudo apt update
sudo apt install git wmctrl
# 2. get the whole repo
# this is where we will put this repo; you can choose any path you want
INSTALL_DIR="$HOME/dev"
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
git clone https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles.git
cd eRCaGuy_dotfiles
# 3. Install the `show_desktop` command
# Install `show_desktop` into ~/bin/
mkdir -p ~/bin
. ~./profile # for a default Ubuntu install, this adds ~/bin to your PATH
# Create a symlink to the script and place it in ~/bin/
# - NB: you must be `cd`ed into the "eRCaGuy_dotfiles/" dir that you just cloned
# before running this cmd.
ln -si "$(pwd)/useful_scripts/show_desktop.sh" ~/bin/show_desktop
# Optional: create a version with your initials prefixed too (mine are `gs_`)
ln -si "$(pwd)/useful_scripts/show_desktop.sh" ~/bin/gs_show_desktop
# test it; this should show your desktop
# - manually press Windows + D to show your open windows again
show_desktop
# 4. Install the show-desktop.desktop launcher file
# - NB: you must be `cd`ed into the "eRCaGuy_dotfiles/" dir that you just cloned
# before running this cmd.
ln -si "$(pwd)/home/Desktop_launchers/show-desktop.desktop" ~/.local/share/applications/
NB:使用上述基于符号链接的说明,您无法删除eRCaGuy_dotfiles存储库。
现在,将"显示桌面"图标添加为您启动器的收藏夹:按下Windows键 --> 搜索"显示桌面" --> 右键单击并选择"添加到收藏夹"。然后,在Ubuntu左侧栏的收藏夹图标中,将其拖放到您希望的位置(我喜欢将其放在最顶部,作为从顶部开始的第一个图标)。
以下是我在Ubuntu 22.04上的示例:
就是这样。享受吧!只需点击图标即可切换显示/隐藏桌面,或者按下Windows(Super)+ D来做同样的事情。