Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login

Gdk::Geometry

class Gdk::Geometry

The Gdk::Geometry gives the window manager information about a window's geometry constraints. Normally you would set these on the GTK+ level using Gtk::Window#set_geometry_hints. Gtk::Window then sets the hints on the Gdk::Window it creates.

Gdk::Window#set_geometry_hints expects the hints to be fully valid already and simply passes them to the window manager; in contrast, 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 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_inc and height_inc 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 1x1 character terminal area, and only terminal sizes on the "character grid" will be allowed.

Here's an example of how the terminal example would be implemented, assuming a terminal area widget called "terminal" and a toplevel window "toplevel":

hints = Gdk::Geometry.new

hints.base_width  = terminal.char_width  # terminal is subclass of Gtk::Widget
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

window.set_geometry_hints(terminal, hints,
                           Gdk::Window::HINT_RESIZE_INC |
                           Gdk::Window::HINT_MIN_SIZE |
                           Gdk::Window::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.

Class Methods

Gdk::Geometry.new
Creates a new Gdk::Geometry.

Instance Methods

set(min_width, min_height, max_width, max_height, base_width, base_height, width_inc, height_inc, min_aspect, max_aspect, gravity)
Sets the all values of properties of Gdk::Geometry.
  • min_width: the minimum width of window
  • min_height: the minimum height of window
  • max_width: the maximum width of window
  • max_height: the maximum height of window
  • base_width: allowed window widths are base_width + width_inc * N where N is any integer (-1 allowed with Gtk::Window)
  • base_height: allowed window heights are base_height + height_inc * N where N is any integer (-1 allowed with Gtk::Window)
  • width_inc: width resize increment
  • height_inc: height resize increment
  • min_aspect: minimum width/height ratio (Float)
  • max_aspect: maximum width/height ratio (Float)
  • gravity: the window gravity (GdkGravity)
  • Returns: self
min_width
Gets the minimum width of window (or -1 to use requisition, with Gtk::Window only)
  • Returns: the minimum width of window
min_width=(width)
Sets the minimum width of window (or -1 to use requisition, with Gtk::Window only)
  • width: the minimum width of window
  • Returns: width
set_min_width(width)
Same as Gdk::Geometry#min_width=
  • width: the minimum width of window
  • Returns: self
min_height
Gets the minimum height of window (or -1 to use requisition, with Gtk::Window only)
  • Returns: the minimum height of window
min_height=(height)
Sets the minimum height of window (or -1 to use requisition, with Gtk::Window only)
  • height: the minimum height of window
  • Returns: height
set_min_height(height)
Same as Gdk::Geometry#min_height=
  • height: the minimum height of window
  • Returns: self
max_width
Gets the maximum width of window (or -1 to use requisition, with Gtk::Window only)
  • Returns: the maximum width of window
max_width=(width)
Sets the maximum width of window (or -1 to use requisition, with Gtk::Window only)
  • width: the maximum width of window
  • Returns: width
set_max_width(width)
Same as Gdk::Geometry#max_width=
  • width: the maximum width of window
  • Returns: self
max_height
Gets the maximum height of window (or -1 to use requisition, with Gtk::Window only)
  • Returns: the maximum height of window
max_height=(height)
Sets the maximum height of window (or -1 to use requisition, with Gtk::Window only)
  • height: the maximum height of window
  • Returns: height
set_max_height(height)
Same as Gdk::Geometry#max_height=
  • height: the maximum height of window
  • Returns: self
base_width
Gets the base width of window. Allowed window widths are base_width + width_inc * N where N is any integer (-1 allowed with Gtk::Window)
  • Returns: the base width.
base_width=(width)
Sets the base width of window. Allowed window widths are base_width + width_inc * N where N is any integer (-1 allowed with Gtk::Window)
  • width: the base width.
  • Returns: width
set_base_width(width)
Same as Gdk::Geometry#base_width=.
  • width: the base width.
  • Returns: self
base_height
Gets the base height of window. Allowed window heights are base_height + height_inc * N where N is any integer (-1 allowed with Gtk::Window)
  • Returns: the base height.
base_height=(height)
Sets the base height of window. Allowed window heights are base_height + height_inc * N where N is any integer (-1 allowed with Gtk::Window)
  • height: the base height.
  • Returns: height
set_base_height(height)
Same as Gdk::Geometry#base_height=.
  • height: the base height.
  • Returns: self
width_inc
Gets the width resize increment
  • Returns: the width resize increment
width_inc=(inc)
Sets the width resize increment
  • inc: the width resize increment
  • Returns: inc
set_width_inc(inc)
Same as Gdk::Geometry#width_inc=.
  • inc: the width resize increment
  • Returns: self
height_inc
Gets the height resize increment
  • Returns: the height resize increment
height_inc=(inc)
Sets the height resize increment
  • inc: the height resize increment
  • Returns: inc
set_height_inc(inc)
Same as Gdk::Geometry#height_inc=.
  • inc: the height resize increment
  • Returns: self
min_aspect
Gets the minimum width/height ratio (Float)
  • Returns: the minimum width/height ratio
min_aspect=(aspect)
Sets the minimum width/height ratio (Float)
  • aspect: the minimum width/height ratio
  • Returns: self
set_min_aspect(aspect)
Same as Gdk::Geometry#min_aspect=.
  • aspect: the minimum width/height ratio
  • Returns: self
max_aspect
Gets the maximum width/height ratio (Float)
  • Returns: the maximum width/height ratio
max_aspect=(aspect)
Sets the maximum width/height ratio (Float)
  • aspect: the maximum width/height ratio
  • Returns: self
set_max_aspect(aspect)
Same as Gdk::Geometry#max_aspect=.
  • aspect: the maximum width/height ratio
  • Returns: self
win_gravity
Gets the window gravity. See Gtk::Window#gravity=.
win_gravity=(gravity)
Sets the window gravity. See Gtk::Window#gravity=.
  • gravity: the window gravity (GdkGravity)
  • Returns: gravity
set_win_gravity(gravity)
Same as Gdk::Geometry#gravity=.
  • gravity: the window gravity (GdkGravity)
  • Returns: self
Last modified:2008/04/10 11:01:32
Keyword(s):
References:[Ruby/GDK] [index-ruby-gdk2] [News_20031116_1] [Gtk::Window] [Gdk::Window] [api-gdk-index] [Gdk::Geometry]