如何使用 python-xlib 管理我的应用程序窗口?

发布于 2024-11-10 03:49:20 字数 767 浏览 0 评论 0原文

我想找到一种 Linux 范围内(只要它使用 X11)的方法来控制我的应用程序的窗口几何形状,我使用 Python 对其进行编程。我所有的研究都指向使用 python-xlib,但它的文档记录却很少。

我想要实现的是:

  • 定义窗口在屏幕上的位置
  • 定义最小和最大尺寸
  • 启用/禁用窗口调整大小
  • 为窗口保留屏幕空间 保留
  • 窗口上方/下方
  • 跳过或不跳过任务栏(又名窗口列表)
  • 设置窗口装饰/ undecorated
  • 设置窗口标志(正常、弹出、对话、启动、停靠、忽略)

注意:我不想使用 Xlib 创建,而是想告诉 X 如何处理我创建的窗口与一些 GUI 库(PyQt for实例)。

我怎样才能做到这一点?我意识到这个问题相当大:你至少有关于我如何抓住我的窗户的提示吗?我可以在模块中的哪里找到答案?

编辑: nm的答案提供了很好的资源,还有Unix StackExchange 上的另一个问答,它提供了一个很好的示例,说明如何控制 X 显示的应用程序窗口。

I would like to find a linux-wide (insofar as it uses X11) way to control the window geometry of my application, which I program using Python. All my researches point to using python-xlib, which happens to be very poorly documented.

What I'd like to achieve is:

  • define position of window on screen
  • define minimum and maximum size
  • enable / disable window resizing
  • reserve screen-space for window
  • keep window above/below
  • skip or not task-bar (aka window list)
  • set window decorated / undecorated
  • set window flags (normal, pop-up, dialogue, splash, dock, ignored)

NB: I don't want to create the with Xlib, instead I want to tell X what to do with the window i created with some GUI library (PyQt for instance).

How can I go about doing this? I realise this question is quite a big one: do you have hints at least as to how I can get hold of my window? Where in the module can I find my answers?

Edit: n.m.'s answer offered great resources, and there is also another Q&A on Unix StackExchange that provides a great example on how to get control on an application window displayed by X.

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

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

发布评论

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

评论(2

不即不离 2024-11-17 03:49:20

您需要知道的第一个关键字是 ICCCM。您需要熟悉 ICCCM 手册(请参阅 http://tronche.com/gui/x/icccm /)和 FreeDesktop 扩展相同(请参阅 http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html)。至于你的问题

如何获得我的窗口?

我不太明白。您调用create_window,该函数将返回您的 Window 对象。或者你还有别的意思吗?

The first keyword you need to know is ICCCM. You need to be familiar with the ICCCM manual (see http://tronche.com/gui/x/icccm/) and the FreeDesktop extensions to the same (see http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html). As for your question

how I can get hold of my window?

I don't quite understand it. You call create_window and the function returns your Window object. Or do you mean something else?

月棠 2024-11-17 03:49:20

昨天才发现这一点,我认为与使用各种 xdotoolwmctrlgtktkinter 相比,它非常棒移动窗口:

def x11_move_window(window_id_dec, x, y, width, height):
    """ Use x11 library to move window From:
        https://gist.github.com/chipolux/13963019c6ca4a2fed348a36c17e1277
    """

    import Xlib.display

    d = Xlib.display.Display()
    window = d.create_resource_object('window', window_id_dec)
    window.configure(x=x, y=y, width=width, height=height, border_width=0,
                     stack_mode=Xlib.X.Above)
    d.sync()

请注意,如果您使用 wmctrl 来获取窗口 ID,则需要在调用 x11_move_window 之前将其从十六进制转换为十进制:

    window_id_hex = \
        os.popen('wmctrl -l | grep gone_fishing.png').read().strip().split()[0]

    window_id_dec = int(window_id_hex, 16)

Just discovered this yesterday and I think it's awesome compared to using variety of xdotool, wmctrl, gtk and tkinter to move windows around:

def x11_move_window(window_id_dec, x, y, width, height):
    """ Use x11 library to move window From:
        https://gist.github.com/chipolux/13963019c6ca4a2fed348a36c17e1277
    """

    import Xlib.display

    d = Xlib.display.Display()
    window = d.create_resource_object('window', window_id_dec)
    window.configure(x=x, y=y, width=width, height=height, border_width=0,
                     stack_mode=Xlib.X.Above)
    d.sync()

Note if you used wmctrl to get your window ID you need to convert it from hexadecimal to decimal before calling x11_move_window:

    window_id_hex = \
        os.popen('wmctrl -l | grep gone_fishing.png').read().strip().split()[0]

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