How can my shell script control the placement of a zenity window?
Asked Answered
M

5

6

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!

Morman answered 11/11, 2009 at 21:20 Comment(1)
Have you tried EWMHIgnoreStateHints and EWMHIgnoreWindowType?Suzannsuzanna
C
5

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.

Cartilage answered 8/11, 2012 at 18:42 Comment(0)
C
2

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).

Cosmopolis answered 6/1, 2011 at 13:27 Comment(1)
Terrifying. I probably won't try this, but +1 for lots of fvwm fu.Morman
S
1

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

Suzannsuzanna answered 12/11, 2009 at 14:33 Comment(6)
+1 for the helpful suggestion, but actually it doesn't work, as I have edited my question to reflect.Morman
No luck. If you have any other ideas, please let me know.Morman
try dropping quotes around "zenity" like this: Style zenity PositionPlacement -0 -0Suzannsuzanna
oh, and try adding EWMHIgnoreStateHints as wellSuzannsuzanna
Please could you mention your xmonad one-liner? Thanks!Threonine
Paul, see xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-Place.html for examplesSuzannsuzanna
V
0

Try devilspie: http://burtonini.com/blog/computers/devilspie/

Variolous answered 24/1, 2010 at 12:39 Comment(0)
L
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

Logic answered 11/12, 2015 at 21:46 Comment(1)
I receive the error message Warning: XTEST extension unavailable on '(null)'. Some functionality may be disabled; See 'man xdotool' for more info. Too few arguments (got 1, minimum is 2) with your example. Do you know what is going wrong?Wholesome

© 2022 - 2024 — McMap. All rights reserved.