主页 HomePage

260818-debian13-dwm-单GUI应用(vscode)

前提:确定网络问题已经解决并真实可用。


1. 安装 Xorg

apt install xorg
apt install xinput

2. 安装 DWM 编译环境

sudo apt install --no-install-recommends \
    build-essential \
    wget \
    ca-certificates \
    libx11-dev \
    libxft-dev \
    libxinerama-dev \
    fonts-dejavu-core

3. 下载源码并编译 DWM

mkdir -p ~/src
cd ~/src
wget https://dl.suckless.org/dwm/dwm-6.8.tar.gz
tar xf dwm-6.8.tar.gz
cd dwm-6.8

3.1 修改 config.mk

nano config.mk

将下述内容:

X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib

修改为:

X11INC = /usr/include
X11LIB = /usr/lib

键盘按下以保存:

Ctrl+X
Y
Enter

3.2 编译并安装

make clean
make
sudo make install
/usr/local/bin/dwm -v

4. 测试 Vanilla DWM

编辑:

nano ~/.xinitrc

复制下述内容:

#!/bin/sh
xterm &
exec /usr/local/bin/dwm

键盘按下以保存:

Ctrl+X
Y
Enter

添加执行权限:

chmod +x ~/.xinitrc

在 Hyper-V 连接器中执行:

startx

键盘按下以退出:

Alt + Shift + Q

5. 制作专用 DWM

进入 DWM 源码目录:

cd ~/src/dwm-6.8
cp config.def.h config.h
nano config.h

将整个 config.h 替换为下面的内容:

/* See LICENSE file for copyright and license details. */

/* appearance */
static const unsigned int borderpx  = 0;
static const unsigned int snap      = 0;
static const int showbar            = 0;
static const int topbar             = 1;

static const char *fonts[]          = { "monospace:size=10" };

static const char col_black[]       = "#000000";
static const char col_white[]       = "#ffffff";

static const char *colors[][3] = {
    /*               fg         bg         border */
    [SchemeNorm] = { col_white, col_black, col_black },
    [SchemeSel]  = { col_white, col_black, col_black },
};

/* one tag only */
static const char *tags[] = {
    "1"
};

/* no application-specific rule yet */
static const Rule rules[] = {
    /* class  instance  title  tags mask  isfloating  monitor */
    { NULL,   NULL,     NULL,  0,         0,          -1 },
};

/* layout */
static const float mfact         = 0.55;
static const int nmaster         = 1;

/*
 * Important for our use case:
 * ignore application size hints when tiled/monocle.
 */
static const int resizehints     = 0;

/* keep focus on real EWMH fullscreen clients */
static const int lockfullscreen  = 1;

static const int refreshrate     = 120;

/*
 * Only one layout:
 *
 * normal windows -> monocle
 * dialog/transient/floating windows -> floating
 */
static const Layout layouts[] = {
    /* symbol  arrange function */
    { "[M]",   monocle },
};


/*
 * dwm.c:spawn() references these two symbols unconditionally.
 * We don't use dmenu, but keep dummy definitions for vanilla dwm.
 */
/*
 * Required by vanilla dwm's spawn().
 * dmenu itself is NOT used or required.
 */
static char dmenumon[2] = "0";
static const char *dmenucmd[] = { NULL };


/*
 * Maintenance modifier.
 *
 * Super + Shift + Q : quit dwm
 * Super + Shift + C : close current client
 */

#define MODKEY Mod1Mask

static const Key keys[] = {
    /* modifier           key   function    argument */
    { MODKEY|ShiftMask,   XK_c, killclient, {0} },
    { MODKEY|ShiftMask,   XK_q, quit,       {0} },
};

/*
 * Debug/maintenance only.
 *
 * These are useful during phase 1 for testing floating dialogs.
 *
 * Super + left mouse  -> move floating window
 * Super + right mouse -> resize floating window
 *
 * They can be removed in phase 2.
 */
static const Button buttons[] = {
    /* click         event mask  button   function     argument */
    { ClkClientWin,  MODKEY,     Button1, movemouse,   {0} },
    { ClkClientWin,  MODKEY,     Button3, resizemouse, {0} },
};

键盘按下以保存:

Ctrl+X
Y
Enter

5.1 重新编译并安装

make clean
make
sudo make install
/usr/local/bin/dwm -v

在 Hyper-V 连接器中执行:

startx

键盘按下以退出:

Super(Alt) + Shift + Q

6. 安装官方 VS Code

6.1 安装基础工具

sudo apt install wget gpg

6.2 导入 Microsoft 官方 Key

wget -qO- https://packages.microsoft.com/keys/microsoft.asc \
    | sudo gpg --dearmor \
    -o /usr/share/keyrings/microsoft.gpg

6.3 创建 VS Code 软件源

sudo nano /etc/apt/sources.list.d/vscode.sources

将下面的内容复制粘贴进去:

Types: deb
URIs: https://packages.microsoft.com/repos/code
Suites: stable
Components: main
Architectures: amd64,arm64,armhf
Signed-By: /usr/share/keyrings/microsoft.gpg

键盘按下以保存:

Ctrl+X
Y
Enter

6.4 安装官方 VS Code

sudo apt update
sudo apt install code
code --version

7. 创建 VS Code 默认工作目录

mkdir -p ~/workspace
ls -ld ~/workspace

8. 配置启动 DWM 与 VS Code

编辑:

nano ~/.xinitrc

将下述内容复制进去:

#!/bin/sh

export XDG_SESSION_TYPE=x11
unset WAYLAND_DISPLAY

# Hyper-V 固定显示模式
/usr/bin/xrandr \
    --output Virtual-1 \
    --mode 1920x1080

# 启动 dwm
/usr/local/bin/dwm &
WM_PID=$!

# 等待 dwm 注册完成
i=0
while [ "$i" -lt 50 ]; do
    if /usr/bin/xprop -root _NET_SUPPORTING_WM_CHECK >/dev/null 2>&1; then
        break
    fi

    i=$((i + 1))
    sleep 0.1
done

# 关键!!!: 直接运行 VS Code GUI 主程序。
# 关键!!!: /usr/bin/code --wait。
/usr/share/code/code \
    --new-window \
    "$HOME/workspace"

CODE_RC=$?

# VS Code 真正退出之后,结束 WM。
kill "$WM_PID" 2>/dev/null
wait "$WM_PID" 2>/dev/null

exit "$CODE_RC"

键盘按下以保存:

Ctrl+X
Y
Enter

设置 .xinitrc 权限:

chmod 700 ~/.xinitrc

9. 启动最终环境

在 Hyper-V 连接器中执行:

startx

启动完成后,可以看到全屏的 VS Code。