How can my shell script control the placement of a zenity window?
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" PositionPlac开发者_StackOverflow中文版ement -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!
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.
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).
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:
- It has
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG
, indicating that it is a dialog window - 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
Try devilspie: http://burtonini.com/blog/computers/devilspie/
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
精彩评论