我的 shell 脚本如何控制 zenity 窗口的位置?

发布于 2024-08-10 21:01:21 字数 1372 浏览 7 评论 0原文

当我的垃圾邮件过滤器守护进程过滤一组邮件时,我使用 zenity 发布简单的通知。目前这条消息被发布到屏幕中间,显得很突兀。我想把它贴到左上角。但是,zenity 不支持 -geometry 选项,该选项被认为是所有 X 应用程序的标准选项,并且其文档提供了用于控制窗口高度和宽度的选项,但没有提供控制位置的选项。

有没有办法控制发布 zenity 窗口的 (x,y) 坐标?

如果没有,有没有办法通过修改 X 资源或窗口管理器(我使用的是 fvwm)来解决这个问题?


编辑:以下内容在~/.fvwm2rcfvwm版本2.5.26)中不起作用:

Style "Information" PositionPlacement -0 -0
Style "Zenity" PositionPlacement -0 -0

它们也不适用于<按照手册页中的建议,将 code>-0 -0 删除。 (zenity --info 的窗口标题是“信息”。)

有趣的是,zenity 忽略了我之前的窗口管理器指令,即默认情况下应手动放置窗口。


编辑

在许多其他令人着迷的信息中,xprop(1) 报告了有关 zenity 窗口的信息:

_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG
WM_NORMAL_HINTS(WM_SIZE_HINTS):
                program specified location: 0, 0
                program specified minimum size: 307 by 128
                program specified maximum size: 307 by 128
                window gravity: NorthWest
WM_CLASS(STRING) = "zenity", "Zenity"
WM_ICON_NAME(STRING) = "Information"
WM_NAME(STRING) = "Information"

尽管这个报告显然令人鼓舞,但该窗口实际上并没有发布在位置 0,0 :-(

我知道 Style 命令正在生效,因为我添加了 !Borders 选项,并且果然 zenity 窗口没有边框……但仍然位于该死的屏幕中央!

I'm using zenity to post a simple notification when my spam-filter daemon filters a group of messages. Currently this message is posted to the middle of the screen, which is obtrusive. I want to post it to the upper left corner. However, zenity does not honor the -geometry option which is supposed to be standard for all X applications, and its documentation gives options for controlling window height and width, but not placement.

Is there a way to control the (x,y) coordinate at which a zenity window is posted?

If not, is there a way to solve this problem by tinkering with X resources or the window manager (I'm using the fvwm)?


EDIT: The following do not work in ~/.fvwm2rc (fvwm version 2.5.26):

Style "Information" PositionPlacement -0 -0
Style "Zenity" PositionPlacement -0 -0

They also don't work with the -0 -0 dropped, as suggested in the man page.
(The window title for zenity --info is "Information".)

Interestingly, zenity was ignoring my earlier window-manager directive that windows should be placed manually by default.


EDIT:

Among many other fascinating pieces of information, xprop(1) reports this about the zenity window:

_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG
WM_NORMAL_HINTS(WM_SIZE_HINTS):
                program specified location: 0, 0
                program specified minimum size: 307 by 128
                program specified maximum size: 307 by 128
                window gravity: NorthWest
WM_CLASS(STRING) = "zenity", "Zenity"
WM_ICON_NAME(STRING) = "Information"
WM_NAME(STRING) = "Information"

Despite this apparently encouraging report, the window is not in fact posted at the location 0,0 :-(

I know the Style command is taking effect because I added the !Borders option, and sure enough the zenity window posts without borders... but still in the center of the damn screen!

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

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

发布评论

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

评论(5

自演自醉 2024-08-17 21:01:21

我通过在子 shell 中使用 wmctrl 来完成此操作。示例:

((sleep .4;wmctrl -r TeaTimer -R TeaTimer -e 0,50,20,-1,-1)
for ((a=$LIMIT; a > 0; a--)); do
# for loop generates text, not shown
done
wmctrl -R TeaTimer
) | zenity --progress --title="TeaTimer" --percentage=0

第一个 wmctrl 将 zenity 移动到左上角,第二个将其移动到
当前工作区。请参阅完整示例

I do it by using wmctrl in a subshell. Example:

((sleep .4;wmctrl -r TeaTimer -R TeaTimer -e 0,50,20,-1,-1)
for ((a=$LIMIT; a > 0; a--)); do
# for loop generates text, not shown
done
wmctrl -R TeaTimer
) | zenity --progress --title="TeaTimer" --percentage=0

First wmctrl moves zenity to upper left, second moves it to
current workspace. See a full example.

一指流沙 2024-08-17 21:01:21

您可以尝试使用“旧”方法来执行此操作,即使用 FvwmEvent。

AddToFunc StartFunction I Module FvwmEvent FvwmEvent-MoveWindow

DestroyModuleConfig FvwmEvent-MoveWindow: *
*FvwmEvent-MoveWindow: Cmd Function
*FvwmEvent-MoveWindow: add_window MoveZenity

DestroyFunc MoveZenity
AddToFunc   MoveZenity
+ I ThisWindow ("zenity") Move -0 -0

如果这仍然不起作用(或者您决定使用 PositionPlacement 使其工作),您可以尝试

BugOpts ExplainWindowPlacement

Fvwm 然后将调试输出写入其日志文件(或控制台,具体取决于您的设置),解释它如何放置窗口(以及为什么要这样做)。

另外仅供参考,如果您想获取有关窗口的信息,您可以使用 FvwmIdent 模块来获取此信息(而不是 xprop,尽管两者都工作正常)。

You could try using the "old" way of doing this, using FvwmEvent.

AddToFunc StartFunction I Module FvwmEvent FvwmEvent-MoveWindow

DestroyModuleConfig FvwmEvent-MoveWindow: *
*FvwmEvent-MoveWindow: Cmd Function
*FvwmEvent-MoveWindow: add_window MoveZenity

DestroyFunc MoveZenity
AddToFunc   MoveZenity
+ I ThisWindow ("zenity") Move -0 -0

If this still doesn't work (or you are determined to get it working using PositionPlacement) you could try

BugOpts ExplainWindowPlacement

Fvwm will then write debugging output to it's logfile (or to the console, depending on your setup) explaining how it is placing windows (and why it is doing so).

Also just fyi, if you want to get information about a window you can use the FvwmIdent module to get this information (instead of xprop, though both work fine).

清晨说晚安 2024-08-17 21:01:21

是的,在窗口管理器的适当帮助下这绝对是可能的。例如,对于 xmonad 来说,这将是一行代码...

我的 fvwm 有点生疏,但看起来类似:

Style "zenity" PositionPlacement -0 -0

在你的 fvwm2rc 中应该可以解决问题。

编辑:请注意小写的“zenity”,因为根据文档,它不仅应该匹配窗口标题,还应该匹配窗口类(您可以使用“xprop”实用程序找到它:启动它并指向有问题的窗口)。

根据 xprop,zenity 窗口有两个有趣的属性:

  1. 它有 _NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG,表明它是一个对话框窗口
  2. 它有 WM_TRANSIENT_FOR(WINDOW): window id #,指示它是一个对话框的主窗口(在我的例子中 - xterm 窗口)

所以,如果我的建议不起作用,那么几乎可以肯定是因为 fvwm 以特殊方式处理对话框 -由于配置或由于硬编码行为。

您可以尝试将“EWMHIgnoreWindowType”添加到 zenity 窗口的样式中,这有望使 fvwm 忽略这些提示

Yes, it is definitely possible with the proper help from window manager. For example, with xmonad it would be one line of code...

My fvwm is little rusty, but it seems like something along the lines of:

Style "zenity" PositionPlacement -0 -0

in your fvwm2rc should do the trick.

EDIT: Notice the lowercase "zenity" since, according to the docs, it should match not only window title, but window class as well (which you can find out using "xprop" utility: launch it and point to window in question).

According to xprop, zenity window has two interesting properties:

  1. It has _NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG, indicating that it is a dialog window
  2. It has WM_TRANSIENT_FOR(WINDOW): window id # <some window id here>, indicating the main window for which it is a dialog (in my case - xterm window)

So, if my suggestion does not work, then it is almost certainly because fvwm handles dialogs in a special way - either due to configuration or due to hardcoded behavoir.

You can try adding "EWMHIgnoreWindowType" to the style of zenity windows, which should hopefuly made fvwm ignore those hints

迟月 2024-08-17 21:01:21

您可以使用 wmctrl 获取 windowid,然后使用 xdotool 将其放置在您想要的任何位置。简单且适用于多种类型的环境。

 ## Arg 1 - Pid of window to move.
 ## Arg 2 - X-Coord.
 ## Arg 3 - Y-Coord. 
function move_win() { 
 xdotool windowmove $(wmctrl -lp | grep ${1} | cut -d' ' -f1) ${2} ${3}
} 

例如 $> move_win $(pidof zenity) 0 0

You can use wmctrl to get the windowid, then xdotool to place it wherever you want. Simple and adaptable to many types of environments.

 ## Arg 1 - Pid of window to move.
 ## Arg 2 - X-Coord.
 ## Arg 3 - Y-Coord. 
function move_win() { 
 xdotool windowmove $(wmctrl -lp | grep ${1} | cut -d' ' -f1) ${2} ${3}
} 

E.g. $> move_win $(pidof zenity) 0 0

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