分类 新教程 下的文章

背景

使用AOSC OS的WPS PDF软件,滚轮滚动过快,阅读体验非常差。再WPS中设置滚动速度无效。

软硬件条件

KDE 5,X11

解决步骤

1、先查看鼠标名称:

xinput list --name-only

示例输出内容:

❯ xinput list --name-only                               
Virtual core pointer
Virtual core XTEST pointer
Razer Razer Ouroboros
Razer Razer Ouroboros Keyboard
BY Tech Gaming Keyboard Mouse
BY Tech Gaming Keyboard Consumer Control
Virtual core keyboard
Virtual core XTEST keyboard
Razer Razer Ouroboros
BY Tech Gaming Keyboard
BY Tech Gaming Keyboard
BY Tech Gaming Keyboard System Control
USB PnP Audio Device
Power Button
Power Button
Razer Razer Ouroboros Keyboard
BY Tech Gaming Keyboard Consumer Control

我的鼠标名称为Razer Razer Ouroboros。下面以此为例叙述。
2、执行xinput list,找到类似↳ Razer Razer Ouroboros id=12 [slave pointer (2)]
3、记下pointer那一行的ID,然后检查当前驱动:

xinput list-props 12 | grep -Ei 'libinput|evdev'

将其中的12替换成你实际的ID。
如果输出主要包含libinput ...,则需要改为evdev。
4、安装驱动。

sudo oma install xf86-input-evdev

注意,请根据你的系统选择合适的包管理器。此外,在aosc os以外的系统上,需要安装的包可能叫xserver-xorg-input-evdev,请结合AI辅助。
5、创建针对该鼠标的evdev设置。

sudo mkdir -p /etc/X11/xorg.conf.d
sudo nano /etc/X11/xorg.conf.d/30-razer-ouroboros-evdev.conf

写入:

Section "InputClass"
    Identifier "Razer Ouroboros evdev"
    MatchProduct "Razer Razer Ouroboros"
    MatchIsPointer "on"
    MatchDevicePath "/dev/input/event*"
    Driver "evdev"
EndSection

6、注销或重启系统。
7、再次执行xinput list-props ID | grep -Ei 'libinput|evdev',如果出现evdev,则证明设置成功。
8、在WPS中测试效果

为什么是evedv?

ibinput是现代Linux桌面默认的输入方案,功能更完整,evdev是较传统的X11输入驱动,处理方式更直接,功能较少,但对部分旧软件兼容性更好,因此切换到evdev能改善滚动表现。

背景

loong64架构的安同操作系统中安装微信后,无法使用中文输入法。

解决方法

1、编辑微信的快捷方式。

sudo vim /usr/share/applications/wechat.desktop

2、将正确的环境变量添加进去。
原来:

[Desktop Entry]
Name=wechat
Name[zh_CN]=微信
Exec=/usr/bin/wechat %U
StartupNotify=true
Terminal=false
Icon=/usr/share/icons/hicolor/256x256/apps/wechat.png
Type=Application
Categories=Utility;
Comment=Wechat Desktop
Comment[zh_CN]=微信桌面版

env GTK_IM_MODULE=fcitx QT_IM_MODULE=fcitx XMODIFIERS=@im=fcitx添加到Exec后面,如下所示:

[Desktop Entry]
Name=wechat
Name[zh_CN]=微信
Exec=env GTK_IM_MODULE=fcitx QT_IM_MODULE=fcitx XMODIFIERS=@im=fcitx /usr/bin/wechat %U
StartupNotify=true
Terminal=false
Icon=/usr/share/icons/hicolor/256x256/apps/wechat.png
Type=Application
Categories=Utility;
Comment=Wechat Desktop
Comment[zh_CN]=微信桌面版

3、保存,重启微信,问题解决。

背景

开发了一个项目,需要打成pip包。

重要概念

pyproject.toml 就是“告诉 Python:这个项目叫什么、依赖什么、怎么打包、打完后生成什么”的配置文件。

步骤

1、目录结构

myproj/
  mypkg/
    __init__.py

2、准备project.toml

[project]
name = "mypkg"
version = "0.1.0"
description = "My package"
requires-python = ">=3.11"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["mypkg"]

3、准备构建工具。

python3 -m venv .pkgbuild
./.pkgbuild/bin/python -m ensurepip --upgrade
./.pkgbuild/bin/python -m pip install -U pip build hatchling -i https://pypi.tuna.tsinghua.edu.cn/simple

4、在项目根目录构建包
这里的“项目根目录”就是有 pyproject.toml 的目录

./.pkgbuild/bin/python -m build --no-isolation

最简模板

  1. 纯库包模板
    适合:别人 import mypkg,但没有命令行入口。

假设目录是:

myproj/
  pyproject.toml
  README.md
  mypkg/
    __init__.py

模板:

[project]
name = "mypkg"
version = "0.1.0"
description = "My Python package"
readme = "README.md"
requires-python = ">=3.11"
license = { text = "MIT" }
authors = [
  { name = "your name" }
]
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["mypkg"]
  1. 带 CLI 的包模板
    适合:安装后能直接运行命令,比如mytool。

假设目录是:

myproj/
  pyproject.toml
  README.md
  mypkg/
    __init__.py
    cli.py

如果 cli.py 里有一个可调用入口,例如:

def main():
    print("hello")

那模板可以写成:

[project]
name = "mypkg"
version = "0.1.0"
description = "My command line tool"
readme = "README.md"
requires-python = ">=3.11"
license = { text = "MIT" }
authors = [
  { name = "your name" }
]
dependencies = []

[project.scripts]
mypkg = "mypkg.cli:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["mypkg"]

这里最关键的是这句:

[project.scripts]
mypkg = "mypkg.cli:main"

意思是安装后可以直接运行 mypkg 命令,它会调用 mypkg/cli.py 里的 main()。

  1. 带资源文件的包模板
    适合:除了 Python 代码,还要把脚本、配置、jar、模板等文件一起打进包里。这个最接近你现在的。

假设目录是:

myproj/
  pyproject.toml
  README.md
  bridge/
    package.json
  softwares/
    tool.jar
  mypkg/
    __init__.py
    cli.py
    resources/
      config.json
    skills/
      demo/
        SKILL.md
        scripts/
          run.sh
          helper.py

模板:

[project]
name = "mypkg"
version = "0.1.0"
description = "My package with bundled resources"
readme = "README.md"
requires-python = ">=3.11"
license = { text = "MIT" }
authors = [
  { name = "your name" }
]
dependencies = []

[project.scripts]
mypkg = "mypkg.cli:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["mypkg"]

[tool.hatch.build]
include = [
  "mypkg/**/*.py",
  "mypkg/**/*.md",
  "mypkg/**/*.sh",
  "mypkg/**/*.json",
]

[tool.hatch.build.targets.sdist]
include = [
  "mypkg/",
  "bridge/",
  "README.md",
]

artifacts = [
  "softwares/**",
]

[tool.hatch.build.targets.wheel.force-include]
"bridge" = "mypkg/bridge"
"softwares" = "mypkg/softwares"

这里最值得你记住的是:

include:选进正常资源
sdist.include:源码包里带什么
artifacts:专门处理像 softwares/ 这种可能被 .gitignore 忽略、但仍然要打包的内容
force-include:把包目录外的目录塞进最终 wheel

背景

在VSCode中使用Roo Code时,遇到终端集成问题,Roo Code无法在终端中执行各种操作,也无法获取输出,非常不方便。

解决步骤

1、检查powershell版本。
按下 Win + R,输入 pwsh,如果报找不到文件pswh,则版本不对,需要升级。
2、在powershell命令行中输入以下命令,安装新版本。

winget search Microsoft.PowerShell
winget install --id Microsoft.PowerShell --source winget

3、用pswh方式打开新的powershell,执行以下命令。

New-Item -Path $PROFILE -ItemType File -Force

在创建的文件中写入以下内容:

if ($env:TERM_PROGRAM -eq "vscode") {
  . "$(code --locate-shell-integration-path pwsh)"
}

4、以管理员方式启动powershell,执行以下命令。

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

5、在VSCode中按下Ctrl + Shift + P,输入Preferences: Open User Settings (JSON),填入以下内容。

    "terminal.integrated.defaultProfile.windows": "PowerShell 7",
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ]
        },
        "PowerShell 7": {
            "path": "你的pwsh.exe路径",
            "args": []
        }
    },

6、在VScode终端中输入以下命令:

$PSVersionTable.PSVersion

看是否有正确输出。

参考资料

https://zhuanlan.zhihu.com/p/25724740375

背景

每次AirPods连接MAC都会被音量吓一跳。

步骤

1、安装Hammerspoon。

brew install hammerspoon --cask

2、创建默认配置。

mkdir -p ~/.hammerspoon
touch ~/.hammerspoon/init.lua

3、在init.lua中写入配置

-- 存储上一次默认音频输出设备的名称
local lastOutputDeviceName = hs.audiodevice.defaultOutputDevice():name()

-- 处理设备变更的回调函数
local function handleDeviceChanges()
-- 获取当前默认音频输出设备的名称
local currentOutputDeviceName = hs.audiodevice.defaultOutputDevice():name()
-- 判断设备名称是否发生了变化
if lastOutputDeviceName ~= currentOutputDeviceName then
-- 判断当前设备是否为蓝牙耳机
if string.find(currentOutputDeviceName, "AirPods") then
-- 连接蓝牙耳机时将音量设置为 20
hs.audiodevice.defaultOutputDevice():setVolume(20)
hs.alert.show("音量已设为 20")
-- 判断上一个设备是否为蓝牙耳机
elseif string.find(lastOutputDeviceName, "AirPods") then
-- 断开蓝牙耳机时将音量设置为 0
hs.audiodevice.defaultOutputDevice():setVolume(0)
hs.alert.show("音量已设为 0")
end
end
-- 更新 lastOutputDeviceName 为当前设备名称
lastOutputDeviceName = currentOutputDeviceName
end

-- 为音频设备变动设置回调函数
hs.audiodevice.watcher.setCallback(handleDeviceChanges)
-- 启动音频设备监听器
hs.audiodevice.watcher.start()

4、重新加载配置。
在启动台搜索Hammerspoon,启动应用。然后在标题栏点击他的图标,然后选择Reload Config。

参考资料

https://www.v2ex.com/t/1011644