我想构建一个Python脚本来检查是否在nautilus中打开了特定目录。
到目前为止,我拥有的最佳解决方案是使用wmctrl -lxp列出所有窗口的方法,这使我得到如下输出:
0x0323d584 0 1006 nautilus.Nautilus namek Downloads
0x0325083a 0 1006 nautilus.Nautilus namek test
0x04400003 0 25536 gvim.Gvim namek yolo_voc.py + (~/code/netharn/netharn/examples) - GVIM4
Run Code Online (Sandbox Code Playgroud)
然后,我检查感兴趣的目录的基本名称是否在nautilus.NautilusWindows的窗口名称中。
这是我刚刚描述的不完整解决方案的代码:
def is_directory_open(dpath):
import ubelt as ub # pip install me! https://github.com/Erotemic/ubelt
import platform
from os.path import basename
import re
computer_name = platform.node()
dname = basename(dpath)
for line in ub.cmd('wmctrl -lxp')['out'].splitlines():
parts = re.split(' *', line)
if len(parts) > 3 and parts[3] == 'nautilus.Nautilus':
if parts[4] == computer_name:
# FIXME: …Run Code Online (Sandbox Code Playgroud) 我知道 Wayland 协议不提供控制屏幕上外壳表面位置的选项。我想找到一种控制窗口/表面放置的方法。我尝试过 xdotool 和 wmctrl 等工具,但它们只能识别 XWayland 窗口。我使用的是 Gnome Shell,因此窗口管理器是 Mutter。为什么地面定位不是 Wayland 协议的一部分?以编程方式控制 Wayland 表面放置的建议方法是什么?
编辑:
Wayland 客户端协议提供了子表面的接口,它足以满足我目前的目的。但是窗口我希望协议包含顶级窗口位置选项。我可以使用 javascript 来制作 gnome-shell 扩展吗?但在这种情况下这并不是一个真正的选择。