如何使用 Python 检查哪个窗口管理器正在运行?

发布于 2024-09-11 08:45:17 字数 48 浏览 4 评论 0 原文

我想检查用户正在使用哪个窗口管理器(如 GNOME 或 KDE 等)。我该怎么做?

I want to check which Window Manager the user is using (like GNOME or KDE etc.). How do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼忆七猫命九 2024-09-18 08:45:17

你不能。程序没有一个中心位置来注册自己来说“嗨,我是窗口管理器”。

例如,我正在运行 xmonad。我只需在我的 ~/.xsession 文件中调用 xmonad 以及其他几个程序来启动它,以便在我登录时启动它。你无法真正察觉到这一点。

You can't. There is no central place where a program registers itself to say "hi, I'm the window manager".

For instance, I'm running xmonad. I simply start this by calling xmonad in my ~/.xsession file along with a couple of other programs to have it start when I login. You cannot really detect that.

紙鸢 2024-09-18 08:45:17

由于您显然使用的是 Linux,因此您可以使用 wmctrl -minxi -Sxx

import subprocess

def get_wm():

    output = subprocess.run(['wmctrl', '-m'], text=True,
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if output.stderr:
        return(output.stderr)
    else:
        return(output.stdout)

print(get_wm())

Since you're apparently using linux, you could use wmctrl -m or inxi -Sxx.

import subprocess

def get_wm():

    output = subprocess.run(['wmctrl', '-m'], text=True,
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if output.stderr:
        return(output.stderr)
    else:
        return(output.stdout)

print(get_wm())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文