> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/di-13-zhang-zhuo-mian-huan-jing/di-13.4-jie-xfce.md).

# 13.4 Xfce

Xfce 是一款基于 GTK+ 的轻量级桌面环境，提供简洁、高效、易于使用的桌面体验。它完全可配置，拥有包含菜单、小程序和应用程序启动器的主面板，提供文件管理器和声音管理器，并支持主题。由于其快速、轻巧、高效的特性，非常适合配置较低或内存受限的计算机。

值得一提的是，Xfce 的 Logo 是一只老鼠 🐀。曾有用户反馈一则轶事，称因 Xfce 的默认壁纸是一只老鼠 🐀，导致电脑屏幕被猫 🐈 抓坏（SanjaytheToilet. \[joke] The default desktop startup screen causes damage to monitor!\[EB/OL]. (2015-08-04)\[2026-04-04]. <https://bugzilla.xfce.org/show_bug.cgi?id=12117>.）。

## 安装 Xfce 桌面环境

* 通过 pkg 安装

```sh
# pkg install xorg xfce wqy-fonts xdg-user-dirs xfce4-goodies 
```

* 或通过 Ports 安装：

```sh
# cd /usr/ports/x11/xorg/ && make install clean
# cd /usr/ports/x11-wm/xfce4 && make install clean # 注意包名中的数字 4
# cd /usr/ports/x11/xfce4-goodies/ && make install clean
# cd /usr/ports/x11-fonts/wqy/ && make install clean
# cd /usr/ports/devel/xdg-user-dirs/ && make install clean
```

登录管理器可考虑使用 LightDM。

### 软件包说明

| 包名              | 作用说明           |
| --------------- | -------------- |
| `xorg`          | X 窗口系统         |
| `xfce`          | Xfce 桌面环境      |
| `wqy-fonts`     | 文泉驿中文字体        |
| `xdg-user-dirs` | 管理用户主目录        |
| `xfce4-goodies` | Xfce 附加组件和插件集合 |

## startx 命令

将 Xfce 启动脚本写入 **\~/.xinitrc** 文件，以便使用 startx 命令启动 Xfce：

```sh
$ echo "/usr/local/etc/xdg/xfce4/xinitrc" > ~/.xinitrc
```

## 启动服务

设置 D-Bus 服务开机自启：

```sh
# service dbus enable
```

## 图片欣赏

![FreeBSD 安装 Xfce](/files/4C1m6TLZiogEg66AokVg)

![FreeBSD 安装 Xfce](/files/mhhAskyyhentmQbFlC8H)

## 全局菜单（可选）

使用 pkg 安装：

```sh
# pkg install xfce4-appmenu-plugin appmenu-gtk-module appmenu-registrar
```

或使用 Ports 安装：

```sh
# cd /usr/ports/x11/xfce4-appmenu-plugin/ && make install clean
# cd /usr/ports/x11/gtk-app-menu/ && make install clean
# cd /usr/ports/x11/appmenu-registrar/ && make install clean
```

查看安装后的说明并据此配置。

```sh
$ xfconf-query -c xsettings -p /Gtk/ShellShowsMenubar -n -t bool -s true  # 启用 GTK 菜单栏显示
$ xfconf-query -c xsettings -p /Gtk/ShellShowsAppmenu -n -t bool -s true  # 启用 GTK 应用菜单显示
$ xfconf-query -c xsettings -p /Gtk/Modules -n -t string -s "appmenu-gtk-module"  # 设置 GTK 模块为 appmenu-gtk-module
```

## XTerm 终端动态标题

### sh

编辑 **\~/.shrc** 文件，写入：

```sh
if [ -t 1 ]; then
  while :; do
    printf '\033]0;%s\007' "$PWD"
    printf '\n$ '
    if ! IFS= read -r cmd; then
      break
    fi
    printf '\033]0;%s\007' "$cmd"
    eval "$cmd"
  done
  exit
fi
```

> **警告**
>
> 此脚本使用 `eval` 存在注入风险！请谨慎使用。

### csh

编辑 **\~/.cshrc** 文件，写入：

```sh
if ( $?TERM && $TERM =~ xterm* ) then
    set host = `hostname`
    alias postcmd 'rehash; printf -- "\033]2;%s\007" "${user}@${host}: ${cwd}"'
endif
```

### tcsh

编辑 **\~/.tcshrc** 文件，写入：

```sh
switch ($TERM)
case xterm*:
    set prompt="%{\033]0;%n@%m: %~\007%}%# "
    breaksw
default:
    set prompt="%# "
    breaksw
endsw
```

### Bash

编辑 **\~/.bashrc** 文件，写入：

```sh
case $TERM in
         xterm*)
             PS1="\[\033]0;\u@\h: \w\007\]bash\\$ "
             ;;
         *)
             PS1="bash\\$ "
             ;;
     esac
```

### Zsh

编辑 **\~/.zshrc** 文件，写入：

```sh
autoload -Uz add-zsh-hook

function xterm_title_precmd () {
	print -Pn -- '\e]2;%n@%m %~\a'
	[[ "$TERM" == 'screen'* ]] && print -Pn -- '\e_\005{2}%n\005{-}@\005{5}%m\005{-} \005{+b 4}%~\005{-}\e\\'
}

function xterm_title_preexec () {
	print -Pn -- '\e]2;%n@%m %~ %# ' && print -n -- "${(q)1}\a"
	[[ "$TERM" == 'screen'* ]] && { print -Pn -- '\e_\005{2}%n\005{-}@\005{5}%m\005{-} \005{+b 4}%~\005{-} %# ' && print -n -- "${(q)1}\e\\"; }
}

if [[ "$TERM" == (Eterm*|alacritty*|aterm*|foot*|gnome*|konsole*|kterm*|putty*|rxvt*|screen*|wezterm*|tmux*|xterm*) ]]; then
	add-zsh-hook -Uz precmd xterm_title_precmd
	add-zsh-hook -Uz preexec xterm_title_preexec
fi
```

### 参考文献

* Oracle Corporation. 6.1 动态设置标题不起作用\[EB/OL]. \[2026-03-25]. <https://docs.oracle.com/cd/E19683-01/817-1951/6mhl8aiii/index.html>. bash 配置来自此处。
* Wamphyre. BSD-XFCE\[EB/OL]. \[2026-03-25]. <https://web.archive.org/web/20260121072214/https://github.com/Wamphyre/BSD-XFCE>. 配置参考集合。
* Arch Linux Project. Zsh\[EB/OL]. \[2026-03-25]. <https://wiki.archlinux.org/title/Zsh>. 该文档提供 Zsh 配置的详细教程，本节 Zsh 配置源自此。

## 故障排除与未竟事宜

如需进一步动态显示当前进程，目前仅 sh 支持该功能。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/di-13-zhang-zhuo-mian-huan-jing/di-13.4-jie-xfce.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
