Package: gdk

CStruct gdk-geometry

Details

The gdk-geometry structure gives the window manager information about a window's geometry constraints. Normally you would set these on the GTK level using the function gtk-window-set-geometry-hints. gtk-window then sets the hints on the gdk-window it creates.

The function gdk-window-set-geometry-hints expects the hints to be fully valid already and simply passes them to the window manager. In contrast, the function gtk-window-set-geometry-hints performs some interpretation. For example, gtk-window will apply the hints to the geometry widget instead of the toplevel window, if you set a geometry widget. Also, the min-width/min-height/max-width/max-height fields may be set to -1, and gtk-window will substitute the size request of the window or geometry widget. If the minimum size hint is not provided, gtk-window will use its requisition as the minimum size. If the minimum size is provided and a geometry widget is set, gtk-window will take the minimum size as the minimum size of the geometry widget rather than the entire window. The base size is treated similarly.

The canonical use-case for the function gtk-window-set-geometry-hints is to get a terminal widget to resize properly. Here, the terminal text area should be the geometry widget. gtk-window will then automatically set the base size to the size of other widgets in the terminal window, such as the menubar and scrollbar. Then, the width-increment and height-incement fields should be set to the size of one character in the terminal. Finally, the base size should be set to the size of one character. The net effect is that the minimum size of the terminal will have a 1 x 1 character terminal area, and only terminal sizes on the "character grid" will be allowed.

Here is an example of how the terminal example would be implemented, assuming a terminal area widget called "terminal" and a toplevel window "toplevel":
GdkGeometry hints;

hints.base_width = terminal->char_width; hints.base_height = terminal->char_height; hints.min_width = terminal->char_width; hints.min_height = terminal->char_height; hints.width_inc = terminal->char_width; hints.height_inc = terminal->char_height;

gtk_window_set_geometry_hints (GTK_WINDOW (toplevel), GTK_WIDGET (terminal), &hints, GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
The other useful fields are the min-aspect and max-aspect fields. These contain a width/height ratio as a floating point number. If a geometry widget is set, the aspect applies to the geometry widget rather than the entire window. The most common use of these hints is probably to set min-aspect and max-aspect to the same value, thus forcing the window to keep a constant aspect ratio.
(defcstruct gdk-geometry
  (min-width :int)
  (min-height :int)
  (max-width :int)
  (max-height :int)
  (base-width :int)
  (base-height :int)
  (width-increment :int)
  (height-increment :int)
  (min-aspect :double)
  (max-aspect :double)
  (win-gravity gdk-gravity))  
min-width
Minimum width of window or -1 to use requisition, with gtk-window only.
min-height
Minimum height of window or -1 to use requisition, with gtk-window only.
max-width
Maximum width of window or -1 to use requisition, with gtk-window only.
max-height
Maximum height of window or -1 to use requisition, with gtk-window only.
base-width
Allowed window widths are base-width + width-inc * N where N is any integer, -1 is allowed with gtk-window.
base-height
Allowed window widths are base-height + height-inc * N where N is any integer, -1 is allowed with gtk-window.
width-increment
Width resize increment.
height-increment
Height resize increment.
min-aspect
Minimum width/height ratio.
max-aspect
Maximum width/height ratio.
win-gravity
Window gravity of type gdk-gravity, see the gtk-window-gravity function.
 

Returned by

See also

2020-9-6