如何真正将窗口置于所有其他窗口之上——Linux PyGTK

发布于 2025-01-03 21:52:24 字数 301 浏览 2 评论 0 原文

我正在尝试制作一个保留在 lxpanel 之上的窗口。

我加载了窗口,使用

import gtk

myWindow = gtk.Window()

myWindow.set_keep_above(True)

myWindow.show_all()

This 确实给了我一个停留在顶部的窗口,它甚至在拖动时设法在 LXpanel 上滑动。当单击其他窗口时,它甚至会保持在顶部,但是当我单击 LXpanel 本身时,lxpanel 会跳到顶部,将我的窗口推到其后面。我怎样才能让这个窗口真正保持在最上面?

I am trying to make a window that will stay on top of lxpanel.

I got the window loaded up, using

import gtk

myWindow = gtk.Window()

myWindow.set_keep_above(True)

myWindow.show_all()

This does indeed give me a window that stays on top, it even manages to slide over LXpanel when dragged. It will even stay on top when other windows are clicked, but when I click on LXpanel itself, lxpanel jumps to the top, pushing my window behind it. How can I make this window REALLY stay on top?

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

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

发布评论

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

评论(3

长亭外,古道边 2025-01-10 21:52:24

此行为由窗口管理器控制,您对此无能为力。

(在我的测试中,尽管 EWMH 推荐,但也许您的 WM 不这样做。)

但是,有一个非常有限的解决方法:如果您假设用户永远不会有多个停靠/面板,您可以将窗口设置为 transient 对于该停靠窗口。通常(同样,取决于窗口管理器)这将使您的窗口保持在停靠窗口之上。


更新:在X11中,即使它们不在同一进程中,您也可以设置瞬态窗口。我发现的最简单的方法是使用 libwnck 获取面板窗口的 XID,然后使用 gdk_window_foreign_new。当然,这在非 X 系统中不起作用。

import wnck
screen = wnck.screen_get_default()
# BUG: There needs to be a small delay between the previous line and the next;
# otherwise get_windows returns an empty list.
windows = screen.get_windows()
panel = windows[1] # For example
panel_xid = panel.get_xid()

import gtk
window = gtk.Window()
window.show_all()
window.window.set_transient_for(gtk.gdk.window_foreign_new(panel_xid))

This behaviour is controlled by your window manager, and you can't really do much about it.

(In my testing, it seems Xfwm4 and Fluxbox puts keep-above windows above dock/panel windows, despite what EWMH recommends, but perhaps your WM doesn't.)

There is, however, a very limited workaround: if you assume that the user will never have more than one dock/panel, you can set your window to be transient for that dock window. Usually (again, depending on window manager) this will keep your window above the dock window.


Update: In X11, you can set transient windows even if they are not in the same process. The simplest way I've found is using libwnck to get the XID of the panel window, then importing that to GDK using gdk_window_foreign_new. Of course, this won't work in non-X systems.

import wnck
screen = wnck.screen_get_default()
# BUG: There needs to be a small delay between the previous line and the next;
# otherwise get_windows returns an empty list.
windows = screen.get_windows()
panel = windows[1] # For example
panel_xid = panel.get_xid()

import gtk
window = gtk.Window()
window.show_all()
window.window.set_transient_for(gtk.gdk.window_foreign_new(panel_xid))
自在安然 2025-01-10 21:52:24

参考页面说 gtk.Window.set_keep_above 只是对窗口管理器的一个请求,可能不会被满足,所以我想说这在所有情况下都不太可能发生。

无论如何,它还提供了一个有趣的信息:

您可以通过 gtk.Widget“window_state_event”信号跟踪上述状态。

也许您可以尝试为该信号设置回调,以确保尽快再次调用 gtk.Window.set_keep_above 。

In the reference page says that gtk.Window.set_keep_above is just a request to the window manager that might not be honored, so I'd say that is unlikely to make that happen under all circumstances.

Anyway, it gives also an interesting piece of information:

You can track the above state via the gtk.Widget "window_state_event" signal.

Maybe you can try to set a callback for that signal to make sure gtk.Window.set_keep_above is called again as soon as possible.

悲念泪 2025-01-10 21:52:24

你可以这样做:

window = gtk.Window(gtk.WINDOW_POPUP)

you can do it like this:

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