A window has both a default widget (to which events are sent if no other widget has been selected and has the focus), and a focus widget (which gets the events and overrides the default widget).
You can set many hints on the window (its minimum and maximum size, its decoration, etc.) but these are only hints to the window manager, which might not respect them.
A useful hint, respected by most window managers, can be used to force some secondary windows to stay on top of the main window on the screen (for instance, so that a smaller window can not be hidden by a bigger one). See the function Set_Transient_For below.
A window can also be modal, i.e. grab all the mouse and keyboard events in the application while it is displayed.
Gtk.Widget.Set_Flags (Widget, Can_Default); Gtk.Widget.Grab_Default (Widget);
The main usage of this function is to force Window to be on top of Parent on the screen at all times. Most window managers respect this hint, even if this is not mandatory.
It's permitted to call this function before showing a window, in which case the window will be kept above when it appears onscreen initially.
You can track the above state via the "window_state_event" signal on Window.
Note that, according to the "Extended Window Manager Hints" specification, the above state is mainly meant for user preferences and should not be used by applications e.g. for drawing attention to their dialogs.
In that example, you would disable startup notification temporarily, show your splash screen, then re-enable it so that showing the main window would automatically result in notification.
Notification is used by the desktop environment to show the user that your application is still loading.
Geometry.Base_* indicates the size that is used by the window manager to report the size: for instance, if Base_Width = 600 and actual width is 200, the window manager will indicate a width of -400.
If your window manager respects the hints (and its doesn't have to), then the user will never be able to resize the window to a size not in Geometry.Min_* .. Geometry.Max_*.
Geometry.*_Inc specifies by which amount the size will be multiplied. For instance, if Width_Inc = 50 and the size reported by the Window Manager is 2x3, then the actual width of the window is 100. Your window's size will always be a multiple of the *_Inc values.
Geometry.*_Aspect specifies the aspect ratio for the window. The window will always be resized so that the ratio between its width and its height remains in the range Min_Aspect .. Max_Aspect.
If Window is hidden, this function calls Gtk.Widget.Show as well.
This function should be used when the user tries to open a window that's already open. Say for example the preferences dialog is currently open, and the user chooses Preferences from the menu a second time; use Present to move the already-open dialog where the user can see it.
If you are calling this function in response to a user interaction, it is preferable to use Present_With_Time.
It's permitted to call this function before showing a window.
You can track stickiness via the "window_state_event" signal on Gtk_Widget.
You can track stickiness via the "window_state_event" signal on Gtk_Widget.
Note: the position is the position of the gravity-determined reference point for the window. The gravity determines two things: first, the location of the reference point in root window coordinates; and second, which point on the window is positioned at the reference point.
By default the gravity is GRAVITY_NORTH_WEST, so the reference point is simply the (x, y) supplied to Move. The top-left corner of the window decorations (aka window frame or border) will be placed at (x, y). Therefore, to position a window at the top left of the screen, you want to use the default gravity (which is GRAVITY_NORTH_WEST) and move the window to 0,0.
To position a window at the bottom right corner of the screen, you would set GRAVITY_SOUTH_EAST, which means that the reference point is at x + the window width and y + the window height, and the bottom-right corner of the window border will be placed at that reference point. So, to place a window in the bottom right corner you would first set gravity to south east, then write: Move (Window, Gdk_Screen_Width - Window_Width, Gdk_Screen_Height - Window_Height);
If you haven't changed the window gravity, its gravity will be GRAVITY_NORTH_WEST. This means that Get_Position gets the position of the top-left corner of the window manager frame for the window. gtk.window.move sets the position of this same top-left corner.
Get_Position is not 100% reliable because the X Window System does not specify a way to obtain the geometry of the decorations placed on a window by the window manager. Thus GTK+ is using a "best guess" that works with most window managers.
Moreover, nearly all window managers are historically broken with respect to their handling of window gravity. So moving a window to its current position as returned by Get_Position tends to result in moving the window slightly. Window managers are slowly getting better over time.
If a window has gravity GRAVITY_STATIC the window manager frame is not relevant, and thus Get_Position will always produce accurate results. However you can't use static gravity to do things like place a window in a corner of the screen, because static gravity ignores the window manager decorations.
If you are saving and restoring your application's window positions, you should know that it's impossible for applications to do this without getting it somewhat wrong because applications do not have sufficient knowledge of window manager state. The Correct Mechanism is to support the session management protocol (see the "GnomeClient" object in the GNOME libraries for example) and allow the window manager to save your window sizes and positions.
If either a size or a position can be extracted from the geometry string, Parse_Geometry returns True and calls Set_Default_Size and/or Move to resize/move the window.
If Parse_Geometry returns True, it will also set the HINT_USER_POS and/or HINT_USER_SIZE hints indicating to the window manager that the size/position of the window was user-specified. This causes most window managers to honor the geometry.
Note that for Parse_Geometry to work as expected, it has to be called when the window has its "final" size, i.e. after calling Show_All on the contents and Set_Geometry_Hints on the window.
See Gdk_Gravity for full details. To briefly summarize, Gravity_North_West means that the reference point is the northwest (top left) corner of the window frame. Gravity_South_East would be the bottom right corner of the frame, and so on. If you want to position the window contents, rather than the window manager's frame, Gravity_Static moves the reference point to the northwest corner of the Gtk_Window itself.
The default window gravity is Gravity_North_West.
This function is used by the linux-fb port to implement managed windows, but it could concievably be used by X-programs that want to do their own window decorations.
It's permitted to call this function before showing a window, in which case the window will be iconified before it ever appears onscreen.
You can track iconification via the "window_state_event" signal on Gtk_Widget.
You can track iconification via the "window_state_event" signal on Gtk_Widget.
It's permitted to call this function before showing a window, in which case the window will be maximized when it appears onscreen initially.
You can track maximization via the "window_state_event" signal on Gtk_Widget.
You can track maximization via the "window_state_event" signal on Gtk_Widget.
Unlike Gtk.Widget.Set_Size_Request, which sets a size request for a widget and thus would keep users from shrinking the window, this function only sets the initial size, just as if the user had resized the window themselves. Users can still shrink the window again as they normally would. Setting a default size of -1 means to use the "natural" default size (the size request of the window).
For more control over a window's initial size and how resizing works, investigate Set_Geometry_Hints.
For some uses, Resize is a more appropriate function. Resize changes the current size of the window, rather than the size to be used on initial display. Resize always affects the window itself, not the geometry widget.
The default size of a window only affects the first time a window is shown; if a window is hidden and re-shown, it will remember the size it had prior to hiding, rather than using the default size.
Windows can't actually be 0x0 in size, they must be at least 1x1, but passing 0 for Width and Height is OK, resulting in a 1x1 default size.
This has no effect on Popup windows (set in call to Gtk_New).
If Resize is called before showing a window for the -- first time, it overrides any default size set with -- Set_Default_Size.
Windows may not be resized smaller than 1 by 1 pixels. However, as a special case, if both Width and Height are set to -1, the best requested size is recomputed for the window, and used.
Note 1: Nearly any use of this function creates a race condition, because the size of the window may change between the time that you get the size and the time that you perform some action assuming that size is the current size. To avoid race conditions, connect to "configure_event" on the window and adjust your size-dependent state to match the size delivered in the Gdk_Event_Configure.
Note 2: The returned size does *not* include the size of the window manager decorations (aka the window frame or border). Those are not drawn by GTK+ and GTK+ has no reliable method of determining their size.
Note 3: If you are getting a window size in order to position the window onscreen, there may be a better way. The preferred way is to simply set the window's semantic type with Set_Type_Hint, which allows the window manager to e.g. center dialogs. Also, if you set the transient parent of dialogs with Set_Transient_For window managers will often center the dialog over its parent window. It's much preferred to let the window manager handle these things rather than doing it yourself, because all apps will behave consistently and according to user prefs if the window manager handles it. Also, the window manager can take the size of the window decorations/border into account, while your application cannot.
In any case, if you insist on application-specified window positioning, there's *still*> a better way than doing it yourself - Set_Position will frequently handle the details for you.
The icon should be provided in whatever size it was naturally drawn; that is, don't scale the image before passing it to GTK+. Scaling is postponed until the last minute, when the desired final size is known, to allow best quality.
If you have your icon hand-drawn in multiple sizes, use Set_Icon_List. Then the best size will be used.
This function is equivalent to calling Set_Icon_List with a single element.
See also Set_Default_Icon_List to set the icon for all windows in your application in one go.
Set_Icon_List allows you to pass in the same icon in several hand-drawn sizes. The list should contain the natural sizes your icon is available in; that is, don't scale the image before passing it to GTK+. Scaling is postponed until the last minute, when the desired final size is known, to allow best quality.
By passing several sizes, you may improve the final image quality of the icon, by reducing or eliminating automatic image scaling.
Recommended sizes to provide: 16x16, 32x32, 48x48 at minimum, and larger images (64x64, 128x128) if you have them.
Note that transient windows (those who have been set transient for another window using Set_Transient_For) will inherit their icon from their transient parent. So there's no need to explicitly set the icon on transient windows.