Zenity dialog windows have excessive height and cannot be resized. Bug workaround anyone?

I've not figured out a method to reduce it's size below the defaults either. You might want to give gxmessage a try instead. It can be reduced, though it too has a minimum size that it can be shrunken to. It does have better control surfaces, IMO, than zenity with respect to font size selection and window dimensions though.

Example

$ gxmessage -center -timeout 60 -font "monospace 9" -buttons "Okay":1 
    -geometry 300x50 --wrap \
    " Hello there friends. Hello there friends. Hello there friends. Hello there friends."

                                       ss of gxmessage

.gtkrc-2.0

If you really want to control the look of GTK+ applications I believe the appropriate way is through the resource file $HOME/.gtkrc-2.0. You can add things like the font in here to override to say a monospace font. For experimentation purposes I made a copy of .gtkrc-2.0 and called it .gtkrc-20.mono8.

The following will make the default font monospace 8:

# $HOME/.gtkrc-2.0.mono8
style "font" {
 font_name = "monospace 8"
}
widget_class "*" style "font"
gtk-font-name = "monospace 8"

You can then control whether this file get's used by GTK+ applications like so:

$ GTK2_RC_FILES=.gtkrc-2.0.mono8 <gtk app>

So here's zenity using defaults:

                    default zenity rc file

Here's zenity using our .gtkrc-2.0.mono8 resource file:

                  mono8 zenity rc file

NOTE: The command used above was this:

$ GTK2_RC_FILES=.gtkrc-2.0.mono8 zenity --info --title="Status" --text \
    "Hello there friends. Hello there friends. Hello there friends."

gtk-parasite

So you can see that we can control GTK+ applications through the .gtkrc-2.0 file but what options can we put in this file. Well there's an app for that 8-), called gtk-parasite. It was in my Fedora repositories as gtkparasite.

Once installed you invoke it against a GTK+ application like so:

$ GTK_MODULES=gtkparasite <gtk app>

So let's invoke zenity:

$ GTK_MODULES=gtkparasite zenity --info --title="Status" --text \
    "Hello there friends. Hello there friends. Hello there friends."

If you mess around with changing spacing in some of the sub-components and hiding the icon you can get the zenity down to a size of 440x65:

                  ss of little zenity


Adding --no-wrap to zenity seems to fix it.

EDIT #1

After more testing, it seems to be a zenity bug.

  • https://bugs.launchpad.net/ubuntu/+source/zenity/+bug/1206760

If text wrapping is used (which in zenity it is used by default), it seems to set the window height based on the minimum window width, with the text wrapping making that size taller. However, the resulting dialog is much wider, causing the text wrapping to be shorter, which results in a window that is too tall for the text.

two workarounds exist

  1. add --no-wrap to turn off wrapping. If your text isn't too wide you can use this, however if it is too wide, the dialog will be too wide for the screen, and you might have to create new lines for manually wrapping, if the text is hard coded. If the text is automatically generated from somewhere, then you might have to look into the fold command to make the text fit.

  2. change --warning --info and --error to --question. For some reason it seems question isn't affected by this, and the dialog size is much more sane. The catch here is that an error dialog will appear with the question icon. Also you'll be presented with "Yes" & "No" buttons instead of just the "OK" button.


It seems to be an old bug and I'm not sure if this bug has been fixed yet. But I still have this problem on my Linux Mint 17.1. However, I found a workaround which works for me and might work for others too:

The --no-wrap option is what does the trick (as mentioned earlier). Omit the --width and --height option or set it to the minimum value you require. And add the --no-wrap option. Now use \n wherever you want to break the line (sentence). The width of the popup will adjust itself to the longest sentence. Use \n\n to create an empty line.

Here is an example:

zenity --warning --title="Zenity | Workaround excessive height" --width=100 --height=100 --no-wrap --text="<big><b>Zenity problem:\n Excessive height with long text.</b></big>\n\nSomehow Zenity's option '<b>--height</b>' doesn't seem to do the job.\nHowever, this doesn't have to spoil your fun! Omit the '<b>--width</b>'\nand '<b>--height</b>' option or set it to the minimum value you require.\nAnd add the '<b>--no-wrap</b>' option. Now use '<b>\\\n</b>' wherever you want\nto break the line (sentence). The width of the popup will adjust\nitself to the longest sentence."

PS. I improved my explanation and replaced the example as it didn't run from the terminal (it ran fine from a script though).

Tags:

Bash

Zenity