1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include "gdk/gdkkeysyms.h"
37 #include "gtkprivate.h"
39 #include "gtkwindow.h"
40 #include "gtkwindow-decorate.h"
41 #include "gtkbindings.h"
42 #include "gtkkeyhash.h"
44 #include "gtkmnemonichash.h"
45 #include "gtkiconfactory.h"
46 #include "gtkicontheme.h"
47 #include "gtkmarshalers.h"
49 #include "gtkbuildable.h"
52 #ifdef GDK_WINDOWING_X11
81 PROP_DESTROY_WITH_PARENT,
86 PROP_SKIP_TASKBAR_HINT,
97 /* Readonly properties */
99 PROP_HAS_TOPLEVEL_FOCUS,
101 /* Writeonly properties */
110 GdkPixmap *icon_pixmap;
111 GdkPixmap *icon_mask;
114 guint using_default_icon : 1;
115 guint using_parent_icon : 1;
116 guint using_themed_icon : 1;
120 GdkGeometry geometry; /* Last set of geometry hints we set */
121 GdkWindowHints flags;
122 GdkRectangle configure_request;
123 } GtkWindowLastGeometryInfo;
125 struct _GtkWindowGeometryInfo
127 /* Properties that the app has set on the window
129 GdkGeometry geometry; /* Geometry hints */
131 GtkWidget *widget; /* subwidget to which hints apply */
132 /* from last gtk_window_resize () - if > 0, indicates that
133 * we should resize to this size.
138 /* From last gtk_window_move () prior to mapping -
139 * only used if initial_pos_set
144 /* Default size - used only the FIRST time we map a window,
149 /* whether to use initial_x, initial_y */
150 guint initial_pos_set : 1;
151 /* CENTER_ALWAYS or other position constraint changed since
152 * we sent the last configure request.
154 guint position_constraints_changed : 1;
156 /* if true, default_width, height come from gtk_window_parse_geometry,
157 * and thus should be multiplied by the increments and affect the
158 * geometry widget only
160 guint default_is_geometry : 1;
162 GtkWindowLastGeometryInfo last;
165 #define GTK_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_WINDOW, GtkWindowPrivate))
167 typedef struct _GtkWindowPrivate GtkWindowPrivate;
169 struct _GtkWindowPrivate
171 GtkMnemonicHash *mnemonic_hash;
173 guint above_initially : 1;
174 guint below_initially : 1;
175 guint fullscreen_initially : 1;
176 guint skips_taskbar : 1;
177 guint skips_pager : 1;
179 guint accept_focus : 1;
180 guint focus_on_map : 1;
182 guint transient_parent_group : 1;
184 guint reset_type_hint : 1;
185 guint opacity_set : 1;
186 guint builder_visible : 1;
188 GdkWindowTypeHint type_hint;
195 static void gtk_window_dispose (GObject *object);
196 static void gtk_window_destroy (GtkObject *object);
197 static void gtk_window_finalize (GObject *object);
198 static void gtk_window_show (GtkWidget *widget);
199 static void gtk_window_hide (GtkWidget *widget);
200 static void gtk_window_map (GtkWidget *widget);
201 static void gtk_window_unmap (GtkWidget *widget);
202 static void gtk_window_realize (GtkWidget *widget);
203 static void gtk_window_unrealize (GtkWidget *widget);
204 static void gtk_window_size_request (GtkWidget *widget,
205 GtkRequisition *requisition);
206 static void gtk_window_size_allocate (GtkWidget *widget,
207 GtkAllocation *allocation);
208 static gint gtk_window_event (GtkWidget *widget,
210 static gboolean gtk_window_map_event (GtkWidget *widget,
212 static gboolean gtk_window_frame_event (GtkWindow *window,
214 static gint gtk_window_configure_event (GtkWidget *widget,
215 GdkEventConfigure *event);
216 static gint gtk_window_key_press_event (GtkWidget *widget,
218 static gint gtk_window_key_release_event (GtkWidget *widget,
220 static gint gtk_window_enter_notify_event (GtkWidget *widget,
221 GdkEventCrossing *event);
222 static gint gtk_window_leave_notify_event (GtkWidget *widget,
223 GdkEventCrossing *event);
224 static gint gtk_window_focus_in_event (GtkWidget *widget,
225 GdkEventFocus *event);
226 static gint gtk_window_focus_out_event (GtkWidget *widget,
227 GdkEventFocus *event);
228 static gint gtk_window_client_event (GtkWidget *widget,
229 GdkEventClient *event);
230 static void gtk_window_check_resize (GtkContainer *container);
231 static gint gtk_window_focus (GtkWidget *widget,
232 GtkDirectionType direction);
233 static void gtk_window_real_set_focus (GtkWindow *window,
236 static void gtk_window_real_activate_default (GtkWindow *window);
237 static void gtk_window_real_activate_focus (GtkWindow *window);
238 static void gtk_window_move_focus (GtkWindow *window,
239 GtkDirectionType dir);
240 static void gtk_window_keys_changed (GtkWindow *window);
241 static void gtk_window_paint (GtkWidget *widget,
243 static gint gtk_window_expose (GtkWidget *widget,
244 GdkEventExpose *event);
245 static void gtk_window_unset_transient_for (GtkWindow *window);
246 static void gtk_window_transient_parent_realized (GtkWidget *parent,
248 static void gtk_window_transient_parent_unrealized (GtkWidget *parent,
251 static GdkScreen *gtk_window_check_screen (GtkWindow *window);
253 static GtkWindowGeometryInfo* gtk_window_get_geometry_info (GtkWindow *window,
256 static void gtk_window_move_resize (GtkWindow *window);
257 static gboolean gtk_window_compare_hints (GdkGeometry *geometry_a,
259 GdkGeometry *geometry_b,
261 static void gtk_window_constrain_size (GtkWindow *window,
262 GdkGeometry *geometry,
268 static void gtk_window_constrain_position (GtkWindow *window,
273 static void gtk_window_compute_hints (GtkWindow *window,
274 GdkGeometry *new_geometry,
276 static void gtk_window_compute_configure_request (GtkWindow *window,
277 GdkRectangle *request,
278 GdkGeometry *geometry,
281 static void gtk_window_set_default_size_internal (GtkWindow *window,
282 gboolean change_width,
284 gboolean change_height,
286 gboolean is_geometry);
288 static void update_themed_icon (GtkIconTheme *theme,
290 static GList *icon_list_from_theme (GtkWidget *widget,
292 static void gtk_window_realize_icon (GtkWindow *window);
293 static void gtk_window_unrealize_icon (GtkWindow *window);
295 static void gtk_window_notify_keys_changed (GtkWindow *window);
296 static GtkKeyHash *gtk_window_get_key_hash (GtkWindow *window);
297 static void gtk_window_free_key_hash (GtkWindow *window);
298 static void gtk_window_on_composited_changed (GdkScreen *screen,
301 static GSList *toplevel_list = NULL;
302 static guint window_signals[LAST_SIGNAL] = { 0 };
303 static GList *default_icon_list = NULL;
304 static gchar *default_icon_name = NULL;
305 static guint default_icon_serial = 0;
306 static gboolean disable_startup_notification = FALSE;
307 static gboolean sent_startup_notification = FALSE;
309 static GQuark quark_gtk_embedded = 0;
310 static GQuark quark_gtk_window_key_hash = 0;
311 static GQuark quark_gtk_window_default_icon_pixmap = 0;
312 static GQuark quark_gtk_window_icon_info = 0;
313 static GQuark quark_gtk_buildable_accels = 0;
315 static GtkBuildableIface *parent_buildable_iface;
317 static void gtk_window_set_property (GObject *object,
321 static void gtk_window_get_property (GObject *object,
327 static void gtk_window_buildable_interface_init (GtkBuildableIface *iface);
328 static void gtk_window_buildable_set_buildable_property (GtkBuildable *buildable,
331 const GValue *value);
332 static void gtk_window_buildable_parser_finished (GtkBuildable *buildable,
333 GtkBuilder *builder);
334 static gboolean gtk_window_buildable_custom_tag_start (GtkBuildable *buildable,
337 const gchar *tagname,
338 GMarkupParser *parser,
340 static void gtk_window_buildable_custom_finished (GtkBuildable *buildable,
343 const gchar *tagname,
347 G_DEFINE_TYPE_WITH_CODE (GtkWindow, gtk_window, GTK_TYPE_BIN,
348 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
349 gtk_window_buildable_interface_init))
352 add_tab_bindings (GtkBindingSet *binding_set,
353 GdkModifierType modifiers,
354 GtkDirectionType direction)
356 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
358 GTK_TYPE_DIRECTION_TYPE, direction);
359 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
361 GTK_TYPE_DIRECTION_TYPE, direction);
365 add_arrow_bindings (GtkBindingSet *binding_set,
367 GtkDirectionType direction)
369 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
371 gtk_binding_entry_add_signal (binding_set, keysym, 0,
373 GTK_TYPE_DIRECTION_TYPE, direction);
374 gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
376 GTK_TYPE_DIRECTION_TYPE, direction);
377 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
379 GTK_TYPE_DIRECTION_TYPE, direction);
380 gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
382 GTK_TYPE_DIRECTION_TYPE, direction);
386 extract_time_from_startup_id (const gchar* startup_id)
388 gchar *timestr = g_strrstr (startup_id, "_TIME");
389 guint32 retval = GDK_CURRENT_TIME;
396 /* Skip past the "_TIME" part */
400 timestamp = strtoul (timestr, &end, 0);
401 if (end != timestr && errno == 0)
409 startup_id_is_fake (const gchar* startup_id)
411 return strncmp (startup_id, "_TIME", 5) == 0;
415 gtk_window_class_init (GtkWindowClass *klass)
417 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
418 GtkObjectClass *object_class;
419 GtkWidgetClass *widget_class;
420 GtkContainerClass *container_class;
421 GtkBindingSet *binding_set;
423 object_class = (GtkObjectClass*) klass;
424 widget_class = (GtkWidgetClass*) klass;
425 container_class = (GtkContainerClass*) klass;
427 quark_gtk_embedded = g_quark_from_static_string ("gtk-embedded");
428 quark_gtk_window_key_hash = g_quark_from_static_string ("gtk-window-key-hash");
429 quark_gtk_window_default_icon_pixmap = g_quark_from_static_string ("gtk-window-default-icon-pixmap");
430 quark_gtk_window_icon_info = g_quark_from_static_string ("gtk-window-icon-info");
431 quark_gtk_buildable_accels = g_quark_from_static_string ("gtk-window-buildable-accels");
433 gobject_class->dispose = gtk_window_dispose;
434 gobject_class->finalize = gtk_window_finalize;
436 gobject_class->set_property = gtk_window_set_property;
437 gobject_class->get_property = gtk_window_get_property;
439 object_class->destroy = gtk_window_destroy;
441 widget_class->show = gtk_window_show;
442 widget_class->hide = gtk_window_hide;
443 widget_class->map = gtk_window_map;
444 widget_class->map_event = gtk_window_map_event;
445 widget_class->unmap = gtk_window_unmap;
446 widget_class->realize = gtk_window_realize;
447 widget_class->unrealize = gtk_window_unrealize;
448 widget_class->size_request = gtk_window_size_request;
449 widget_class->size_allocate = gtk_window_size_allocate;
450 widget_class->configure_event = gtk_window_configure_event;
451 widget_class->key_press_event = gtk_window_key_press_event;
452 widget_class->key_release_event = gtk_window_key_release_event;
453 widget_class->enter_notify_event = gtk_window_enter_notify_event;
454 widget_class->leave_notify_event = gtk_window_leave_notify_event;
455 widget_class->focus_in_event = gtk_window_focus_in_event;
456 widget_class->focus_out_event = gtk_window_focus_out_event;
457 widget_class->client_event = gtk_window_client_event;
458 widget_class->focus = gtk_window_focus;
460 widget_class->expose_event = gtk_window_expose;
462 container_class->check_resize = gtk_window_check_resize;
464 klass->set_focus = gtk_window_real_set_focus;
465 klass->frame_event = gtk_window_frame_event;
467 klass->activate_default = gtk_window_real_activate_default;
468 klass->activate_focus = gtk_window_real_activate_focus;
469 klass->move_focus = gtk_window_move_focus;
470 klass->keys_changed = gtk_window_keys_changed;
472 g_type_class_add_private (gobject_class, sizeof (GtkWindowPrivate));
475 g_object_class_install_property (gobject_class,
477 g_param_spec_enum ("type",
479 P_("The type of the window"),
480 GTK_TYPE_WINDOW_TYPE,
482 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
484 g_object_class_install_property (gobject_class,
486 g_param_spec_string ("title",
488 P_("The title of the window"),
490 GTK_PARAM_READWRITE));
492 g_object_class_install_property (gobject_class,
494 g_param_spec_string ("role",
496 P_("Unique identifier for the window to be used when restoring a session"),
498 GTK_PARAM_READWRITE));
501 * GtkWindow:startup-id:
503 * The :startup-id is a write-only property for setting window's
504 * startup notification identifier. See gtk_window_set_startup_id()
509 g_object_class_install_property (gobject_class,
511 g_param_spec_string ("startup-id",
513 P_("Unique startup identifier for the window used by startup-notification"),
515 GTK_PARAM_WRITABLE));
517 g_object_class_install_property (gobject_class,
519 g_param_spec_boolean ("allow-shrink",
521 /* xgettext:no-c-format */
522 P_("If TRUE, the window has no mimimum size. Setting this to TRUE is 99% of the time a bad idea"),
524 GTK_PARAM_READWRITE));
526 g_object_class_install_property (gobject_class,
528 g_param_spec_boolean ("allow-grow",
530 P_("If TRUE, users can expand the window beyond its minimum size"),
532 GTK_PARAM_READWRITE));
534 g_object_class_install_property (gobject_class,
536 g_param_spec_boolean ("resizable",
538 P_("If TRUE, users can resize the window"),
540 GTK_PARAM_READWRITE));
542 g_object_class_install_property (gobject_class,
544 g_param_spec_boolean ("modal",
546 P_("If TRUE, the window is modal (other windows are not usable while this one is up)"),
548 GTK_PARAM_READWRITE));
550 g_object_class_install_property (gobject_class,
552 g_param_spec_enum ("window-position",
553 P_("Window Position"),
554 P_("The initial position of the window"),
555 GTK_TYPE_WINDOW_POSITION,
557 GTK_PARAM_READWRITE));
559 g_object_class_install_property (gobject_class,
561 g_param_spec_int ("default-width",
563 P_("The default width of the window, used when initially showing the window"),
567 GTK_PARAM_READWRITE));
569 g_object_class_install_property (gobject_class,
571 g_param_spec_int ("default-height",
572 P_("Default Height"),
573 P_("The default height of the window, used when initially showing the window"),
577 GTK_PARAM_READWRITE));
579 g_object_class_install_property (gobject_class,
580 PROP_DESTROY_WITH_PARENT,
581 g_param_spec_boolean ("destroy-with-parent",
582 P_("Destroy with Parent"),
583 P_("If this window should be destroyed when the parent is destroyed"),
585 GTK_PARAM_READWRITE));
587 g_object_class_install_property (gobject_class,
589 g_param_spec_object ("icon",
591 P_("Icon for this window"),
593 GTK_PARAM_READWRITE));
596 * GtkWindow:icon-name:
598 * The :icon-name property specifies the name of the themed icon to
599 * use as the window icon. See #GtkIconTheme for more details.
603 g_object_class_install_property (gobject_class,
605 g_param_spec_string ("icon-name",
607 P_("Name of the themed icon for this window"),
609 GTK_PARAM_READWRITE));
611 g_object_class_install_property (gobject_class,
613 g_param_spec_object ("screen",
615 P_("The screen where this window will be displayed"),
617 GTK_PARAM_READWRITE));
619 g_object_class_install_property (gobject_class,
621 g_param_spec_boolean ("is-active",
623 P_("Whether the toplevel is the current active window"),
625 GTK_PARAM_READABLE));
627 g_object_class_install_property (gobject_class,
628 PROP_HAS_TOPLEVEL_FOCUS,
629 g_param_spec_boolean ("has-toplevel-focus",
630 P_("Focus in Toplevel"),
631 P_("Whether the input focus is within this GtkWindow"),
633 GTK_PARAM_READABLE));
635 g_object_class_install_property (gobject_class,
637 g_param_spec_enum ("type-hint",
639 P_("Hint to help the desktop environment understand what kind of window this is and how to treat it."),
640 GDK_TYPE_WINDOW_TYPE_HINT,
641 GDK_WINDOW_TYPE_HINT_NORMAL,
642 GTK_PARAM_READWRITE));
644 g_object_class_install_property (gobject_class,
645 PROP_SKIP_TASKBAR_HINT,
646 g_param_spec_boolean ("skip-taskbar-hint",
648 P_("TRUE if the window should not be in the task bar."),
650 GTK_PARAM_READWRITE));
652 g_object_class_install_property (gobject_class,
653 PROP_SKIP_PAGER_HINT,
654 g_param_spec_boolean ("skip-pager-hint",
656 P_("TRUE if the window should not be in the pager."),
658 GTK_PARAM_READWRITE));
660 g_object_class_install_property (gobject_class,
662 g_param_spec_boolean ("urgency-hint",
664 P_("TRUE if the window should be brought to the user's attention."),
666 GTK_PARAM_READWRITE));
669 * GtkWindow:accept-focus-hint:
671 * Whether the window should receive the input focus.
675 g_object_class_install_property (gobject_class,
677 g_param_spec_boolean ("accept-focus",
679 P_("TRUE if the window should receive the input focus."),
681 GTK_PARAM_READWRITE));
684 * GtkWindow:focus-on-map-hint:
686 * Whether the window should receive the input focus when mapped.
690 g_object_class_install_property (gobject_class,
692 g_param_spec_boolean ("focus-on-map",
694 P_("TRUE if the window should receive the input focus when mapped."),
696 GTK_PARAM_READWRITE));
699 * GtkWindow:decorated:
701 * Whether the window should be decorated by the window manager.
705 g_object_class_install_property (gobject_class,
707 g_param_spec_boolean ("decorated",
709 P_("Whether the window should be decorated by the window manager"),
711 GTK_PARAM_READWRITE));
714 * GtkWindow:deletable:
716 * Whether the window frame should have a close button.
720 g_object_class_install_property (gobject_class,
722 g_param_spec_boolean ("deletable",
724 P_("Whether the window frame should have a close button"),
726 GTK_PARAM_READWRITE));
732 * The window gravity of the window. See gtk_window_move() and #GdkGravity for
733 * more details about window gravity.
737 g_object_class_install_property (gobject_class,
739 g_param_spec_enum ("gravity",
741 P_("The window gravity of the window"),
743 GDK_GRAVITY_NORTH_WEST,
744 GTK_PARAM_READWRITE));
748 * GtkWindow:transient-for:
750 * The transient parent of the window. See gtk_window_set_transient_for() for
751 * more details about transient windows.
755 g_object_class_install_property (gobject_class,
757 g_param_spec_object ("transient-for",
758 P_("Transient for Window"),
759 P_("The transient parent of the dialog"),
761 GTK_PARAM_READWRITE| G_PARAM_CONSTRUCT));
766 * The requested opacity of the window. See gtk_window_set_opacity() for
767 * more details about window opacity.
771 g_object_class_install_property (gobject_class,
773 g_param_spec_double ("opacity",
774 P_("Opacity for Window"),
775 P_("The opacity of the window, from 0 to 1"),
779 GTK_PARAM_READWRITE));
781 window_signals[SET_FOCUS] =
782 g_signal_new (I_("set-focus"),
783 G_TYPE_FROM_CLASS (gobject_class),
785 G_STRUCT_OFFSET (GtkWindowClass, set_focus),
787 _gtk_marshal_VOID__OBJECT,
791 window_signals[FRAME_EVENT] =
792 g_signal_new (I_("frame-event"),
793 G_TYPE_FROM_CLASS (gobject_class),
795 G_STRUCT_OFFSET(GtkWindowClass, frame_event),
796 _gtk_boolean_handled_accumulator, NULL,
797 _gtk_marshal_BOOLEAN__BOXED,
802 * GtkWindow::activate-focus:
803 * @window: the window which received the signal
805 * The ::activate-default signal is a
806 * <link linkend="keybinding-signals">keybinding signal</link>
807 * which gets emitted when the user activates the currently
808 * focused widget of @window.
810 window_signals[ACTIVATE_FOCUS] =
811 g_signal_new (I_("activate-focus"),
812 G_TYPE_FROM_CLASS (gobject_class),
813 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
814 G_STRUCT_OFFSET (GtkWindowClass, activate_focus),
816 _gtk_marshal_VOID__VOID,
821 * GtkWindow::activate-default:
822 * @window: the window which received the signal
824 * The ::activate-default signal is a
825 * <link linkend="keybinding-signals">keybinding signal</link>
826 * which gets emitted when the user activates the default widget
829 window_signals[ACTIVATE_DEFAULT] =
830 g_signal_new (I_("activate-default"),
831 G_TYPE_FROM_CLASS (gobject_class),
832 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
833 G_STRUCT_OFFSET (GtkWindowClass, activate_default),
835 _gtk_marshal_VOID__VOID,
840 * GtkWindow::keys-changed:
841 * @window: the window which received the signal
843 * The ::keys-changed signal gets emitted when the set of accelerators
844 * or mnemonics that are associated with @window changes.
846 window_signals[KEYS_CHANGED] =
847 g_signal_new (I_("keys-changed"),
848 G_TYPE_FROM_CLASS (gobject_class),
850 G_STRUCT_OFFSET (GtkWindowClass, keys_changed),
852 _gtk_marshal_VOID__VOID,
860 binding_set = gtk_binding_set_by_class (klass);
862 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
863 "activate-focus", 0);
864 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
865 "activate-focus", 0);
867 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
868 "activate-default", 0);
869 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
870 "activate-default", 0);
871 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
872 "activate-default", 0);
874 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
875 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
876 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
877 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
879 add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
880 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
881 add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
882 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
886 gtk_window_init (GtkWindow *window)
888 GdkColormap *colormap;
889 GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
891 GTK_WIDGET_UNSET_FLAGS (window, GTK_NO_WINDOW);
892 GTK_WIDGET_SET_FLAGS (window, GTK_TOPLEVEL);
894 GTK_PRIVATE_SET_FLAG (window, GTK_ANCHORED);
896 gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
898 window->title = NULL;
899 window->wmclass_name = g_strdup (g_get_prgname ());
900 window->wmclass_class = g_strdup (gdk_get_program_class ());
901 window->wm_role = NULL;
902 window->geometry_info = NULL;
903 window->type = GTK_WINDOW_TOPLEVEL;
904 window->focus_widget = NULL;
905 window->default_widget = NULL;
906 window->configure_request_count = 0;
907 window->allow_shrink = FALSE;
908 window->allow_grow = TRUE;
909 window->configure_notify_received = FALSE;
910 window->position = GTK_WIN_POS_NONE;
911 window->need_default_size = TRUE;
912 window->need_default_position = TRUE;
913 window->modal = FALSE;
914 window->frame = NULL;
915 window->has_frame = FALSE;
916 window->frame_left = 0;
917 window->frame_right = 0;
918 window->frame_top = 0;
919 window->frame_bottom = 0;
920 window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
921 window->gravity = GDK_GRAVITY_NORTH_WEST;
922 window->decorated = TRUE;
923 window->mnemonic_modifier = GDK_MOD1_MASK;
924 window->screen = gdk_screen_get_default ();
926 priv->accept_focus = TRUE;
927 priv->focus_on_map = TRUE;
928 priv->deletable = TRUE;
929 priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
931 priv->startup_id = NULL;
933 colormap = _gtk_widget_peek_colormap ();
935 gtk_widget_set_colormap (GTK_WIDGET (window), colormap);
937 g_object_ref_sink (window);
938 window->has_user_ref_count = TRUE;
939 toplevel_list = g_slist_prepend (toplevel_list, window);
941 gtk_decorated_window_init (window);
943 g_signal_connect (window->screen, "composited-changed",
944 G_CALLBACK (gtk_window_on_composited_changed), window);
948 gtk_window_set_property (GObject *object,
955 window = GTK_WINDOW (object);
960 window->type = g_value_get_enum (value);
963 gtk_window_set_title (window, g_value_get_string (value));
966 gtk_window_set_role (window, g_value_get_string (value));
968 case PROP_STARTUP_ID:
969 gtk_window_set_startup_id (window, g_value_get_string (value));
971 case PROP_ALLOW_SHRINK:
972 window->allow_shrink = g_value_get_boolean (value);
973 gtk_widget_queue_resize (GTK_WIDGET (window));
975 case PROP_ALLOW_GROW:
976 window->allow_grow = g_value_get_boolean (value);
977 gtk_widget_queue_resize (GTK_WIDGET (window));
978 g_object_notify (G_OBJECT (window), "resizable");
981 window->allow_grow = g_value_get_boolean (value);
982 gtk_widget_queue_resize (GTK_WIDGET (window));
983 g_object_notify (G_OBJECT (window), "allow-grow");
986 gtk_window_set_modal (window, g_value_get_boolean (value));
989 gtk_window_set_position (window, g_value_get_enum (value));
991 case PROP_DEFAULT_WIDTH:
992 gtk_window_set_default_size_internal (window,
993 TRUE, g_value_get_int (value),
996 case PROP_DEFAULT_HEIGHT:
997 gtk_window_set_default_size_internal (window,
999 TRUE, g_value_get_int (value), FALSE);
1001 case PROP_DESTROY_WITH_PARENT:
1002 gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
1005 gtk_window_set_icon (window,
1006 g_value_get_object (value));
1008 case PROP_ICON_NAME:
1009 gtk_window_set_icon_name (window, g_value_get_string (value));
1012 gtk_window_set_screen (window, g_value_get_object (value));
1014 case PROP_TYPE_HINT:
1015 gtk_window_set_type_hint (window,
1016 g_value_get_enum (value));
1018 case PROP_SKIP_TASKBAR_HINT:
1019 gtk_window_set_skip_taskbar_hint (window,
1020 g_value_get_boolean (value));
1022 case PROP_SKIP_PAGER_HINT:
1023 gtk_window_set_skip_pager_hint (window,
1024 g_value_get_boolean (value));
1026 case PROP_URGENCY_HINT:
1027 gtk_window_set_urgency_hint (window,
1028 g_value_get_boolean (value));
1030 case PROP_ACCEPT_FOCUS:
1031 gtk_window_set_accept_focus (window,
1032 g_value_get_boolean (value));
1034 case PROP_FOCUS_ON_MAP:
1035 gtk_window_set_focus_on_map (window,
1036 g_value_get_boolean (value));
1038 case PROP_DECORATED:
1039 gtk_window_set_decorated (window, g_value_get_boolean (value));
1041 case PROP_DELETABLE:
1042 gtk_window_set_deletable (window, g_value_get_boolean (value));
1045 gtk_window_set_gravity (window, g_value_get_enum (value));
1047 case PROP_TRANSIENT_FOR:
1048 gtk_window_set_transient_for (window, g_value_get_object (value));
1051 gtk_window_set_opacity (window, g_value_get_double (value));
1054 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1060 gtk_window_get_property (GObject *object,
1066 GtkWindowPrivate *priv;
1068 window = GTK_WINDOW (object);
1069 priv = GTK_WINDOW_GET_PRIVATE (window);
1073 GtkWindowGeometryInfo *info;
1075 g_value_set_enum (value, window->type);
1078 g_value_set_string (value, window->wm_role);
1081 g_value_set_string (value, window->title);
1083 case PROP_ALLOW_SHRINK:
1084 g_value_set_boolean (value, window->allow_shrink);
1086 case PROP_ALLOW_GROW:
1087 g_value_set_boolean (value, window->allow_grow);
1089 case PROP_RESIZABLE:
1090 g_value_set_boolean (value, window->allow_grow);
1093 g_value_set_boolean (value, window->modal);
1096 g_value_set_enum (value, window->position);
1098 case PROP_DEFAULT_WIDTH:
1099 info = gtk_window_get_geometry_info (window, FALSE);
1101 g_value_set_int (value, -1);
1103 g_value_set_int (value, info->default_width);
1105 case PROP_DEFAULT_HEIGHT:
1106 info = gtk_window_get_geometry_info (window, FALSE);
1108 g_value_set_int (value, -1);
1110 g_value_set_int (value, info->default_height);
1112 case PROP_DESTROY_WITH_PARENT:
1113 g_value_set_boolean (value, window->destroy_with_parent);
1116 g_value_set_object (value, gtk_window_get_icon (window));
1118 case PROP_ICON_NAME:
1119 g_value_set_string (value, gtk_window_get_icon_name (window));
1122 g_value_set_object (value, window->screen);
1124 case PROP_IS_ACTIVE:
1125 g_value_set_boolean (value, window->is_active);
1127 case PROP_HAS_TOPLEVEL_FOCUS:
1128 g_value_set_boolean (value, window->has_toplevel_focus);
1130 case PROP_TYPE_HINT:
1131 g_value_set_enum (value, priv->type_hint);
1133 case PROP_SKIP_TASKBAR_HINT:
1134 g_value_set_boolean (value,
1135 gtk_window_get_skip_taskbar_hint (window));
1137 case PROP_SKIP_PAGER_HINT:
1138 g_value_set_boolean (value,
1139 gtk_window_get_skip_pager_hint (window));
1141 case PROP_URGENCY_HINT:
1142 g_value_set_boolean (value,
1143 gtk_window_get_urgency_hint (window));
1145 case PROP_ACCEPT_FOCUS:
1146 g_value_set_boolean (value,
1147 gtk_window_get_accept_focus (window));
1149 case PROP_FOCUS_ON_MAP:
1150 g_value_set_boolean (value,
1151 gtk_window_get_focus_on_map (window));
1153 case PROP_DECORATED:
1154 g_value_set_boolean (value, gtk_window_get_decorated (window));
1156 case PROP_DELETABLE:
1157 g_value_set_boolean (value, gtk_window_get_deletable (window));
1160 g_value_set_enum (value, gtk_window_get_gravity (window));
1162 case PROP_TRANSIENT_FOR:
1163 g_value_set_object (value, gtk_window_get_transient_for (window));
1166 g_value_set_double (value, gtk_window_get_opacity (window));
1169 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1175 gtk_window_buildable_interface_init (GtkBuildableIface *iface)
1177 parent_buildable_iface = g_type_interface_peek_parent (iface);
1178 iface->set_buildable_property = gtk_window_buildable_set_buildable_property;
1179 iface->parser_finished = gtk_window_buildable_parser_finished;
1180 iface->custom_tag_start = gtk_window_buildable_custom_tag_start;
1181 iface->custom_finished = gtk_window_buildable_custom_finished;
1185 gtk_window_buildable_set_buildable_property (GtkBuildable *buildable,
1186 GtkBuilder *builder,
1188 const GValue *value)
1190 GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (buildable);
1192 if (strcmp (name, "visible") == 0 && g_value_get_boolean (value))
1193 priv->builder_visible = TRUE;
1195 parent_buildable_iface->set_buildable_property (buildable, builder, name, value);
1199 gtk_window_buildable_parser_finished (GtkBuildable *buildable,
1200 GtkBuilder *builder)
1202 GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (buildable);
1206 if (priv->builder_visible)
1207 gtk_widget_show (GTK_WIDGET (buildable));
1209 accels = g_object_get_qdata (G_OBJECT (buildable), quark_gtk_buildable_accels);
1210 for (l = accels; l; l = l->next)
1212 object = gtk_builder_get_object (builder, l->data);
1215 g_warning ("Unknown accel group %s specified in window %s",
1216 (const gchar*)l->data, gtk_buildable_get_name (buildable));
1219 gtk_window_add_accel_group (GTK_WINDOW (buildable),
1220 GTK_ACCEL_GROUP (object));
1224 g_object_set_qdata (G_OBJECT (buildable), quark_gtk_buildable_accels, NULL);
1226 parent_buildable_iface->parser_finished (buildable, builder);
1232 } GSListSubParserData;
1235 window_start_element (GMarkupParseContext *context,
1236 const gchar *element_name,
1237 const gchar **names,
1238 const gchar **values,
1243 GSListSubParserData *data = (GSListSubParserData*)user_data;
1245 if (strcmp (element_name, "group") == 0)
1247 for (i = 0; names[i]; i++)
1249 if (strcmp (names[i], "name") == 0)
1250 data->items = g_slist_prepend (data->items, g_strdup (values[i]));
1253 else if (strcmp (element_name, "accel-groups") == 0)
1256 g_warning ("Unsupported tag type for GtkWindow: %s\n",
1261 static const GMarkupParser window_parser =
1263 window_start_element
1267 gtk_window_buildable_custom_tag_start (GtkBuildable *buildable,
1268 GtkBuilder *builder,
1270 const gchar *tagname,
1271 GMarkupParser *parser,
1274 GSListSubParserData *parser_data;
1276 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
1277 tagname, parser, data))
1280 if (strcmp (tagname, "accel-groups") == 0)
1282 parser_data = g_slice_new0 (GSListSubParserData);
1283 parser_data->items = NULL;
1284 parser_data->object = G_OBJECT (buildable);
1286 *parser = window_parser;
1287 *data = parser_data;
1295 gtk_window_buildable_custom_finished (GtkBuildable *buildable,
1296 GtkBuilder *builder,
1298 const gchar *tagname,
1301 GSListSubParserData *data;
1303 parent_buildable_iface->custom_finished (buildable, builder, child,
1304 tagname, user_data);
1306 if (strcmp (tagname, "accel-groups") != 0)
1309 data = (GSListSubParserData*)user_data;
1311 g_object_set_qdata_full (G_OBJECT (buildable), quark_gtk_buildable_accels,
1312 data->items, (GDestroyNotify) g_slist_free);
1314 g_slice_free (GSListSubParserData, data);
1319 * @type: type of window
1321 * Creates a new #GtkWindow, which is a toplevel window that can
1322 * contain other widgets. Nearly always, the type of the window should
1323 * be #GTK_WINDOW_TOPLEVEL. If you're implementing something like a
1324 * popup menu from scratch (which is a bad idea, just use #GtkMenu),
1325 * you might use #GTK_WINDOW_POPUP. #GTK_WINDOW_POPUP is not for
1326 * dialogs, though in some other toolkits dialogs are called "popups".
1327 * In GTK+, #GTK_WINDOW_POPUP means a pop-up menu or pop-up tooltip.
1328 * On X11, popup windows are not controlled by the <link
1329 * linkend="gtk-X11-arch">window manager</link>.
1331 * If you simply want an undecorated window (no window borders), use
1332 * gtk_window_set_decorated(), don't use #GTK_WINDOW_POPUP.
1334 * Return value: a new #GtkWindow.
1337 gtk_window_new (GtkWindowType type)
1341 g_return_val_if_fail (type >= GTK_WINDOW_TOPLEVEL && type <= GTK_WINDOW_POPUP, NULL);
1343 window = g_object_new (GTK_TYPE_WINDOW, NULL);
1345 window->type = type;
1347 return GTK_WIDGET (window);
1351 * gtk_window_set_title:
1352 * @window: a #GtkWindow
1353 * @title: title of the window
1355 * Sets the title of the #GtkWindow. The title of a window will be
1356 * displayed in its title bar; on the X Window System, the title bar
1357 * is rendered by the <link linkend="gtk-X11-arch">window
1358 * manager</link>, so exactly how the title appears to users may vary
1359 * according to a user's exact configuration. The title should help a
1360 * user distinguish this window from other windows they may have
1361 * open. A good title might include the application name and current
1362 * document filename, for example.
1366 gtk_window_set_title (GtkWindow *window,
1371 g_return_if_fail (GTK_IS_WINDOW (window));
1373 new_title = g_strdup (title);
1374 g_free (window->title);
1375 window->title = new_title;
1377 if (GTK_WIDGET_REALIZED (window))
1379 gdk_window_set_title (GTK_WIDGET (window)->window, window->title);
1381 gtk_decorated_window_set_title (window, title);
1384 g_object_notify (G_OBJECT (window), "title");
1388 * gtk_window_get_title:
1389 * @window: a #GtkWindow
1391 * Retrieves the title of the window. See gtk_window_set_title().
1393 * Return value: the title of the window, or %NULL if none has
1394 * been set explicitely. The returned string is owned by the widget
1395 * and must not be modified or freed.
1397 G_CONST_RETURN gchar *
1398 gtk_window_get_title (GtkWindow *window)
1400 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
1402 return window->title;
1406 * gtk_window_set_wmclass:
1407 * @window: a #GtkWindow
1408 * @wmclass_name: window name hint
1409 * @wmclass_class: window class hint
1411 * Don't use this function. It sets the X Window System "class" and
1412 * "name" hints for a window. According to the ICCCM, you should
1413 * always set these to the same value for all windows in an
1414 * application, and GTK+ sets them to that value by default, so calling
1415 * this function is sort of pointless. However, you may want to call
1416 * gtk_window_set_role() on each window in your application, for the
1417 * benefit of the session manager. Setting the role allows the window
1418 * manager to restore window positions when loading a saved session.
1422 gtk_window_set_wmclass (GtkWindow *window,
1423 const gchar *wmclass_name,
1424 const gchar *wmclass_class)
1426 g_return_if_fail (GTK_IS_WINDOW (window));
1428 g_free (window->wmclass_name);
1429 window->wmclass_name = g_strdup (wmclass_name);
1431 g_free (window->wmclass_class);
1432 window->wmclass_class = g_strdup (wmclass_class);
1434 if (GTK_WIDGET_REALIZED (window))
1435 g_warning ("gtk_window_set_wmclass: shouldn't set wmclass after window is realized!\n");
1439 * gtk_window_set_role:
1440 * @window: a #GtkWindow
1441 * @role: unique identifier for the window to be used when restoring a session
1443 * This function is only useful on X11, not with other GTK+ targets.
1445 * In combination with the window title, the window role allows a
1446 * <link linkend="gtk-X11-arch">window manager</link> to identify "the
1447 * same" window when an application is restarted. So for example you
1448 * might set the "toolbox" role on your app's toolbox window, so that
1449 * when the user restarts their session, the window manager can put
1450 * the toolbox back in the same place.
1452 * If a window already has a unique title, you don't need to set the
1453 * role, since the WM can use the title to identify the window when
1454 * restoring the session.
1458 gtk_window_set_role (GtkWindow *window,
1463 g_return_if_fail (GTK_IS_WINDOW (window));
1465 new_role = g_strdup (role);
1466 g_free (window->wm_role);
1467 window->wm_role = new_role;
1469 if (GTK_WIDGET_REALIZED (window))
1470 gdk_window_set_role (GTK_WIDGET (window)->window, window->wm_role);
1472 g_object_notify (G_OBJECT (window), "role");
1476 * gtk_window_set_startup_id:
1477 * @window: a #GtkWindow
1478 * @startup_id: a string with startup-notification identifier
1480 * Startup notification identifiers are used by desktop environment to
1481 * track application startup, to provide user feedback and other
1482 * features. This function changes the corresponding property on the
1483 * underlying GdkWindow. Normally, startup identifier is managed
1484 * automatically and you should only use this function in special cases
1485 * like transferring focus from other processes. You should use this
1486 * function before calling gtk_window_present() or any equivalent
1487 * function generating a window map event.
1489 * This function is only useful on X11, not with other GTK+ targets.
1494 gtk_window_set_startup_id (GtkWindow *window,
1495 const gchar *startup_id)
1497 GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
1499 g_return_if_fail (GTK_IS_WINDOW (window));
1501 g_free (priv->startup_id);
1502 priv->startup_id = g_strdup (startup_id);
1504 if (GTK_WIDGET_REALIZED (window))
1506 guint32 timestamp = extract_time_from_startup_id (priv->startup_id);
1508 #ifdef GDK_WINDOWING_X11
1509 if (timestamp != GDK_CURRENT_TIME)
1510 gdk_x11_window_set_user_time (GTK_WIDGET (window)->window, timestamp);
1513 /* Here we differentiate real and "fake" startup notification IDs,
1514 * constructed on purpose just to pass interaction timestamp
1516 if (startup_id_is_fake (priv->startup_id))
1517 gtk_window_present_with_time (window, timestamp);
1520 gdk_window_set_startup_id (GTK_WIDGET (window)->window,
1523 /* If window is mapped, terminate the startup-notification too */
1524 if (GTK_WIDGET_MAPPED (window) && !disable_startup_notification)
1525 gdk_notify_startup_complete_with_id (priv->startup_id);
1529 g_object_notify (G_OBJECT (window), "startup-id");
1533 * gtk_window_get_role:
1534 * @window: a #GtkWindow
1536 * Returns the role of the window. See gtk_window_set_role() for
1537 * further explanation.
1539 * Return value: the role of the window if set, or %NULL. The
1540 * returned is owned by the widget and must not be modified
1543 G_CONST_RETURN gchar *
1544 gtk_window_get_role (GtkWindow *window)
1546 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
1548 return window->wm_role;
1552 * gtk_window_set_focus:
1553 * @window: a #GtkWindow
1554 * @focus: widget to be the new focus widget, or %NULL to unset
1555 * any focus widget for the toplevel window.
1557 * If @focus is not the current focus widget, and is focusable, sets
1558 * it as the focus widget for the window. If @focus is %NULL, unsets
1559 * the focus widget for this window. To set the focus to a particular
1560 * widget in the toplevel, it is usually more convenient to use
1561 * gtk_widget_grab_focus() instead of this function.
1564 gtk_window_set_focus (GtkWindow *window,
1567 g_return_if_fail (GTK_IS_WINDOW (window));
1570 g_return_if_fail (GTK_IS_WIDGET (focus));
1571 g_return_if_fail (GTK_WIDGET_CAN_FOCUS (focus));
1575 gtk_widget_grab_focus (focus);
1578 /* Clear the existing focus chain, so that when we focus into
1579 * the window again, we start at the beginnning.
1581 GtkWidget *widget = window->focus_widget;
1584 while (widget->parent)
1586 widget = widget->parent;
1587 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
1591 _gtk_window_internal_set_focus (window, NULL);
1596 _gtk_window_internal_set_focus (GtkWindow *window,
1599 g_return_if_fail (GTK_IS_WINDOW (window));
1601 if ((window->focus_widget != focus) ||
1602 (focus && !GTK_WIDGET_HAS_FOCUS (focus)))
1603 g_signal_emit (window, window_signals[SET_FOCUS], 0, focus);
1607 * gtk_window_set_default:
1608 * @window: a #GtkWindow
1609 * @default_widget: widget to be the default, or %NULL to unset the
1610 * default widget for the toplevel.
1612 * The default widget is the widget that's activated when the user
1613 * presses Enter in a dialog (for example). This function sets or
1614 * unsets the default widget for a #GtkWindow about. When setting
1615 * (rather than unsetting) the default widget it's generally easier to
1616 * call gtk_widget_grab_focus() on the widget. Before making a widget
1617 * the default widget, you must set the #GTK_CAN_DEFAULT flag on the
1618 * widget you'd like to make the default using GTK_WIDGET_SET_FLAGS().
1621 gtk_window_set_default (GtkWindow *window,
1622 GtkWidget *default_widget)
1624 g_return_if_fail (GTK_IS_WINDOW (window));
1627 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (default_widget));
1629 if (window->default_widget != default_widget)
1631 GtkWidget *old_default_widget = NULL;
1634 g_object_ref (default_widget);
1636 if (window->default_widget)
1638 old_default_widget = window->default_widget;
1640 if (window->focus_widget != window->default_widget ||
1641 !GTK_WIDGET_RECEIVES_DEFAULT (window->default_widget))
1642 GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
1643 gtk_widget_queue_draw (window->default_widget);
1646 window->default_widget = default_widget;
1648 if (window->default_widget)
1650 if (window->focus_widget == NULL ||
1651 !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget))
1652 GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
1653 gtk_widget_queue_draw (window->default_widget);
1656 if (old_default_widget)
1657 g_object_notify (G_OBJECT (old_default_widget), "has-default");
1661 g_object_notify (G_OBJECT (default_widget), "has-default");
1662 g_object_unref (default_widget);
1668 * gtk_window_get_default_widget:
1669 * @window: a #GtkWindow
1671 * Returns the default widget for @window. See gtk_window_set_default()
1674 * Returns: the default widget, or %NULL if there is none.
1679 gtk_window_get_default_widget (GtkWindow *window)
1681 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
1683 return window->default_widget;
1687 gtk_window_set_policy_internal (GtkWindow *window,
1688 gboolean allow_shrink,
1689 gboolean allow_grow,
1690 gboolean auto_shrink)
1692 window->allow_shrink = (allow_shrink != FALSE);
1693 window->allow_grow = (allow_grow != FALSE);
1695 g_object_freeze_notify (G_OBJECT (window));
1696 g_object_notify (G_OBJECT (window), "allow-shrink");
1697 g_object_notify (G_OBJECT (window), "allow-grow");
1698 g_object_notify (G_OBJECT (window), "resizable");
1699 g_object_thaw_notify (G_OBJECT (window));
1701 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
1705 gtk_window_set_policy (GtkWindow *window,
1706 gboolean allow_shrink,
1707 gboolean allow_grow,
1708 gboolean auto_shrink)
1710 g_return_if_fail (GTK_IS_WINDOW (window));
1712 gtk_window_set_policy_internal (window, allow_shrink, allow_grow, auto_shrink);
1716 handle_keys_changed (gpointer data)
1720 window = GTK_WINDOW (data);
1722 if (window->keys_changed_handler)
1724 g_source_remove (window->keys_changed_handler);
1725 window->keys_changed_handler = 0;
1728 g_signal_emit (window, window_signals[KEYS_CHANGED], 0);
1734 gtk_window_notify_keys_changed (GtkWindow *window)
1736 if (!window->keys_changed_handler)
1737 window->keys_changed_handler = gdk_threads_add_idle (handle_keys_changed, window);
1741 * gtk_window_add_accel_group:
1742 * @window: window to attach accelerator group to
1743 * @accel_group: a #GtkAccelGroup
1745 * Associate @accel_group with @window, such that calling
1746 * gtk_accel_groups_activate() on @window will activate accelerators
1750 gtk_window_add_accel_group (GtkWindow *window,
1751 GtkAccelGroup *accel_group)
1753 g_return_if_fail (GTK_IS_WINDOW (window));
1754 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
1756 _gtk_accel_group_attach (accel_group, G_OBJECT (window));
1757 g_signal_connect_object (accel_group, "accel-changed",
1758 G_CALLBACK (gtk_window_notify_keys_changed),
1759 window, G_CONNECT_SWAPPED);
1760 gtk_window_notify_keys_changed (window);
1764 * gtk_window_remove_accel_group:
1765 * @window: a #GtkWindow
1766 * @accel_group: a #GtkAccelGroup
1768 * Reverses the effects of gtk_window_add_accel_group().
1771 gtk_window_remove_accel_group (GtkWindow *window,
1772 GtkAccelGroup *accel_group)
1774 g_return_if_fail (GTK_IS_WINDOW (window));
1775 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
1777 g_signal_handlers_disconnect_by_func (accel_group,
1778 gtk_window_notify_keys_changed,
1780 _gtk_accel_group_detach (accel_group, G_OBJECT (window));
1781 gtk_window_notify_keys_changed (window);
1784 static GtkMnemonicHash *
1785 gtk_window_get_mnemonic_hash (GtkWindow *window,
1788 GtkWindowPrivate *private = GTK_WINDOW_GET_PRIVATE (window);
1789 if (!private->mnemonic_hash && create)
1790 private->mnemonic_hash = _gtk_mnemonic_hash_new ();
1792 return private->mnemonic_hash;
1796 * gtk_window_add_mnemonic:
1797 * @window: a #GtkWindow
1798 * @keyval: the mnemonic
1799 * @target: the widget that gets activated by the mnemonic
1801 * Adds a mnemonic to this window.
1804 gtk_window_add_mnemonic (GtkWindow *window,
1808 g_return_if_fail (GTK_IS_WINDOW (window));
1809 g_return_if_fail (GTK_IS_WIDGET (target));
1811 _gtk_mnemonic_hash_add (gtk_window_get_mnemonic_hash (window, TRUE),
1813 gtk_window_notify_keys_changed (window);
1817 * gtk_window_remove_mnemonic:
1818 * @window: a #GtkWindow
1819 * @keyval: the mnemonic
1820 * @target: the widget that gets activated by the mnemonic
1822 * Removes a mnemonic from this window.
1825 gtk_window_remove_mnemonic (GtkWindow *window,
1829 g_return_if_fail (GTK_IS_WINDOW (window));
1830 g_return_if_fail (GTK_IS_WIDGET (target));
1832 _gtk_mnemonic_hash_remove (gtk_window_get_mnemonic_hash (window, TRUE),
1834 gtk_window_notify_keys_changed (window);
1838 * gtk_window_mnemonic_activate:
1839 * @window: a #GtkWindow
1840 * @keyval: the mnemonic
1841 * @modifier: the modifiers
1842 * @returns: %TRUE if the activation is done.
1844 * Activates the targets associated with the mnemonic.
1847 gtk_window_mnemonic_activate (GtkWindow *window,
1849 GdkModifierType modifier)
1851 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1853 if (window->mnemonic_modifier == (modifier & gtk_accelerator_get_default_mod_mask ()))
1855 GtkMnemonicHash *mnemonic_hash = gtk_window_get_mnemonic_hash (window, FALSE);
1857 return _gtk_mnemonic_hash_activate (mnemonic_hash, keyval);
1864 * gtk_window_set_mnemonic_modifier:
1865 * @window: a #GtkWindow
1866 * @modifier: the modifier mask used to activate
1867 * mnemonics on this window.
1869 * Sets the mnemonic modifier for this window.
1872 gtk_window_set_mnemonic_modifier (GtkWindow *window,
1873 GdkModifierType modifier)
1875 g_return_if_fail (GTK_IS_WINDOW (window));
1876 g_return_if_fail ((modifier & ~GDK_MODIFIER_MASK) == 0);
1878 window->mnemonic_modifier = modifier;
1879 gtk_window_notify_keys_changed (window);
1883 * gtk_window_get_mnemonic_modifier:
1884 * @window: a #GtkWindow
1886 * Returns the mnemonic modifier for this window. See
1887 * gtk_window_set_mnemonic_modifier().
1889 * Return value: the modifier mask used to activate
1890 * mnemonics on this window.
1893 gtk_window_get_mnemonic_modifier (GtkWindow *window)
1895 g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
1897 return window->mnemonic_modifier;
1901 * gtk_window_set_position:
1902 * @window: a #GtkWindow.
1903 * @position: a position constraint.
1905 * Sets a position constraint for this window. If the old or new
1906 * constraint is %GTK_WIN_POS_CENTER_ALWAYS, this will also cause
1907 * the window to be repositioned to satisfy the new constraint.
1910 gtk_window_set_position (GtkWindow *window,
1911 GtkWindowPosition position)
1913 g_return_if_fail (GTK_IS_WINDOW (window));
1915 if (position == GTK_WIN_POS_CENTER_ALWAYS ||
1916 window->position == GTK_WIN_POS_CENTER_ALWAYS)
1918 GtkWindowGeometryInfo *info;
1920 info = gtk_window_get_geometry_info (window, TRUE);
1922 /* this flag causes us to re-request the CENTER_ALWAYS
1923 * constraint in gtk_window_move_resize(), see
1924 * comment in that function.
1926 info->position_constraints_changed = TRUE;
1928 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
1931 window->position = position;
1933 g_object_notify (G_OBJECT (window), "window-position");
1937 * gtk_window_activate_focus:
1938 * @window: a #GtkWindow
1940 * Activates the current focused widget within the window.
1942 * Return value: %TRUE if a widget got activated.
1945 gtk_window_activate_focus (GtkWindow *window)
1947 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1949 if (window->focus_widget && GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
1950 return gtk_widget_activate (window->focus_widget);
1956 * gtk_window_get_focus:
1957 * @window: a #GtkWindow
1959 * Retrieves the current focused widget within the window.
1960 * Note that this is the widget that would have the focus
1961 * if the toplevel window focused; if the toplevel window
1962 * is not focused then <literal>GTK_WIDGET_HAS_FOCUS (widget)</literal> will
1963 * not be %TRUE for the widget.
1965 * Return value: the currently focused widget, or %NULL if there is none.
1968 gtk_window_get_focus (GtkWindow *window)
1970 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
1972 return window->focus_widget;
1976 * gtk_window_activate_default:
1977 * @window: a #GtkWindow
1979 * Activates the default widget for the window, unless the current
1980 * focused widget has been configured to receive the default action
1981 * (see #GTK_RECEIVES_DEFAULT in #GtkWidgetFlags), in which case the
1982 * focused widget is activated.
1984 * Return value: %TRUE if a widget got activated.
1987 gtk_window_activate_default (GtkWindow *window)
1989 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1991 if (window->default_widget && GTK_WIDGET_IS_SENSITIVE (window->default_widget) &&
1992 (!window->focus_widget || !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget)))
1993 return gtk_widget_activate (window->default_widget);
1994 else if (window->focus_widget && GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
1995 return gtk_widget_activate (window->focus_widget);
2001 * gtk_window_set_modal:
2002 * @window: a #GtkWindow
2003 * @modal: whether the window is modal
2005 * Sets a window modal or non-modal. Modal windows prevent interaction
2006 * with other windows in the same application. To keep modal dialogs
2007 * on top of main application windows, use
2008 * gtk_window_set_transient_for() to make the dialog transient for the
2009 * parent; most <link linkend="gtk-X11-arch">window managers</link>
2010 * will then disallow lowering the dialog below the parent.
2015 gtk_window_set_modal (GtkWindow *window,
2018 g_return_if_fail (GTK_IS_WINDOW (window));
2020 modal = modal != FALSE;
2021 if (window->modal == modal)
2024 window->modal = modal;
2026 /* adjust desired modality state */
2027 if (GTK_WIDGET_REALIZED (window))
2029 GtkWidget *widget = GTK_WIDGET (window);
2032 gdk_window_set_modal_hint (widget->window, TRUE);
2034 gdk_window_set_modal_hint (widget->window, FALSE);
2037 if (GTK_WIDGET_VISIBLE (window))
2040 gtk_grab_add (GTK_WIDGET (window));
2042 gtk_grab_remove (GTK_WIDGET (window));
2045 g_object_notify (G_OBJECT (window), "modal");
2049 * gtk_window_get_modal:
2050 * @window: a #GtkWindow
2052 * Returns whether the window is modal. See gtk_window_set_modal().
2054 * Return value: %TRUE if the window is set to be modal and
2055 * establishes a grab when shown
2058 gtk_window_get_modal (GtkWindow *window)
2060 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
2062 return window->modal;
2066 * gtk_window_list_toplevels:
2068 * Returns a list of all existing toplevel windows. The widgets
2069 * in the list are not individually referenced. If you want
2070 * to iterate through the list and perform actions involving
2071 * callbacks that might destroy the widgets, you <emphasis>must</emphasis> call
2072 * <literal>g_list_foreach (result, (GFunc)g_object_ref, NULL)</literal> first, and
2073 * then unref all the widgets afterwards.
2075 * Return value: list of toplevel widgets
2078 gtk_window_list_toplevels (void)
2083 for (slist = toplevel_list; slist; slist = slist->next)
2084 list = g_list_prepend (list, slist->data);
2090 gtk_window_add_embedded_xid (GtkWindow *window, GdkNativeWindow xid)
2092 GList *embedded_windows;
2094 g_return_if_fail (GTK_IS_WINDOW (window));
2096 embedded_windows = g_object_get_qdata (G_OBJECT (window), quark_gtk_embedded);
2097 if (embedded_windows)
2098 g_object_steal_qdata (G_OBJECT (window), quark_gtk_embedded);
2099 embedded_windows = g_list_prepend (embedded_windows,
2100 GUINT_TO_POINTER (xid));
2102 g_object_set_qdata_full (G_OBJECT (window), quark_gtk_embedded,
2105 (GDestroyNotify) g_list_free : NULL);
2109 gtk_window_remove_embedded_xid (GtkWindow *window, GdkNativeWindow xid)
2111 GList *embedded_windows;
2114 g_return_if_fail (GTK_IS_WINDOW (window));
2116 embedded_windows = g_object_get_qdata (G_OBJECT (window), quark_gtk_embedded);
2117 if (embedded_windows)
2118 g_object_steal_qdata (G_OBJECT (window), quark_gtk_embedded);
2120 node = g_list_find (embedded_windows, GUINT_TO_POINTER (xid));
2123 embedded_windows = g_list_remove_link (embedded_windows, node);
2124 g_list_free_1 (node);
2127 g_object_set_qdata_full (G_OBJECT (window), quark_gtk_embedded,
2130 (GDestroyNotify) g_list_free : NULL);
2134 _gtk_window_reposition (GtkWindow *window,
2138 g_return_if_fail (GTK_IS_WINDOW (window));
2140 gtk_window_move (window, x, y);
2144 gtk_window_dispose (GObject *object)
2146 GtkWindow *window = GTK_WINDOW (object);
2148 gtk_window_set_focus (window, NULL);
2149 gtk_window_set_default (window, NULL);
2151 G_OBJECT_CLASS (gtk_window_parent_class)->dispose (object);
2155 parent_destroyed_callback (GtkWindow *parent, GtkWindow *child)
2157 gtk_widget_destroy (GTK_WIDGET (child));
2161 connect_parent_destroyed (GtkWindow *window)
2163 if (window->transient_parent)
2165 g_signal_connect (window->transient_parent,
2167 G_CALLBACK (parent_destroyed_callback),
2173 disconnect_parent_destroyed (GtkWindow *window)
2175 if (window->transient_parent)
2177 g_signal_handlers_disconnect_by_func (window->transient_parent,
2178 parent_destroyed_callback,
2184 gtk_window_transient_parent_realized (GtkWidget *parent,
2187 if (GTK_WIDGET_REALIZED (window))
2188 gdk_window_set_transient_for (window->window, parent->window);
2192 gtk_window_transient_parent_unrealized (GtkWidget *parent,
2195 if (GTK_WIDGET_REALIZED (window))
2196 gdk_property_delete (window->window,
2197 gdk_atom_intern_static_string ("WM_TRANSIENT_FOR"));
2201 gtk_window_transient_parent_screen_changed (GtkWindow *parent,
2205 gtk_window_set_screen (window, parent->screen);
2209 gtk_window_unset_transient_for (GtkWindow *window)
2211 GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
2213 if (window->transient_parent)
2215 g_signal_handlers_disconnect_by_func (window->transient_parent,
2216 gtk_window_transient_parent_realized,
2218 g_signal_handlers_disconnect_by_func (window->transient_parent,
2219 gtk_window_transient_parent_unrealized,
2221 g_signal_handlers_disconnect_by_func (window->transient_parent,
2222 gtk_window_transient_parent_screen_changed,
2224 g_signal_handlers_disconnect_by_func (window->transient_parent,
2225 gtk_widget_destroyed,
2226 &window->transient_parent);
2228 if (window->destroy_with_parent)
2229 disconnect_parent_destroyed (window);
2231 window->transient_parent = NULL;
2233 if (priv->transient_parent_group)
2235 priv->transient_parent_group = FALSE;
2236 gtk_window_group_remove_window (window->group,
2243 * gtk_window_set_transient_for:
2244 * @window: a #GtkWindow
2245 * @parent: parent window
2247 * Dialog windows should be set transient for the main application
2248 * window they were spawned from. This allows <link
2249 * linkend="gtk-X11-arch">window managers</link> to e.g. keep the
2250 * dialog on top of the main window, or center the dialog over the
2251 * main window. gtk_dialog_new_with_buttons() and other convenience
2252 * functions in GTK+ will sometimes call
2253 * gtk_window_set_transient_for() on your behalf.
2255 * On Windows, this function puts the child window on top of the parent,
2256 * much as the window manager would have done on X.
2260 gtk_window_set_transient_for (GtkWindow *window,
2263 GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
2265 g_return_if_fail (GTK_IS_WINDOW (window));
2266 g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
2267 g_return_if_fail (window != parent);
2269 if (window->transient_parent)
2271 if (GTK_WIDGET_REALIZED (window) &&
2272 GTK_WIDGET_REALIZED (window->transient_parent) &&
2273 (!parent || !GTK_WIDGET_REALIZED (parent)))
2274 gtk_window_transient_parent_unrealized (GTK_WIDGET (window->transient_parent),
2275 GTK_WIDGET (window));
2277 gtk_window_unset_transient_for (window);
2280 window->transient_parent = parent;
2284 g_signal_connect (parent, "destroy",
2285 G_CALLBACK (gtk_widget_destroyed),
2286 &window->transient_parent);
2287 g_signal_connect (parent, "realize",
2288 G_CALLBACK (gtk_window_transient_parent_realized),
2290 g_signal_connect (parent, "unrealize",
2291 G_CALLBACK (gtk_window_transient_parent_unrealized),
2293 g_signal_connect (parent, "notify::screen",
2294 G_CALLBACK (gtk_window_transient_parent_screen_changed),
2297 gtk_window_set_screen (window, parent->screen);
2299 if (window->destroy_with_parent)
2300 connect_parent_destroyed (window);
2302 if (GTK_WIDGET_REALIZED (window) &&
2303 GTK_WIDGET_REALIZED (parent))
2304 gtk_window_transient_parent_realized (GTK_WIDGET (parent),
2305 GTK_WIDGET (window));
2309 gtk_window_group_add_window (parent->group, window);
2310 priv->transient_parent_group = TRUE;
2316 * gtk_window_get_transient_for:
2317 * @window: a #GtkWindow
2319 * Fetches the transient parent for this window. See
2320 * gtk_window_set_transient_for().
2322 * Return value: the transient parent for this window, or %NULL
2323 * if no transient parent has been set.
2326 gtk_window_get_transient_for (GtkWindow *window)
2328 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
2330 return window->transient_parent;
2334 * gtk_window_set_opacity:
2335 * @window: a #GtkWindow
2336 * @opacity: desired opacity, between 0 and 1
2338 * Request the windowing system to make @window partially transparent,
2339 * with opacity 0 being fully transparent and 1 fully opaque. (Values
2340 * of the opacity parameter are clamped to the [0,1] range.) On X11
2341 * this has any effect only on X screens with a compositing manager
2342 * running. See gtk_widget_is_composited(). On Windows it should work
2345 * Note that setting a window's opacity after the window has been
2346 * shown causes it to flicker once on Windows.
2351 gtk_window_set_opacity (GtkWindow *window,
2354 GtkWindowPrivate *priv;
2356 g_return_if_fail (GTK_IS_WINDOW (window));
2358 priv = GTK_WINDOW_GET_PRIVATE (window);
2362 else if (opacity > 1.0)
2365 priv->opacity_set = TRUE;
2366 priv->opacity = opacity;
2368 if (GTK_WIDGET_REALIZED (window))
2369 gdk_window_set_opacity (GTK_WIDGET (window)->window, priv->opacity);
2373 * gtk_window_get_opacity:
2374 * @window: a #GtkWindow
2376 * Fetches the requested opacity for this window. See
2377 * gtk_window_set_opacity().
2379 * Return value: the requested opacity for this window.
2384 gtk_window_get_opacity (GtkWindow *window)
2386 GtkWindowPrivate *priv;
2388 g_return_val_if_fail (GTK_IS_WINDOW (window), 0.0);
2390 priv = GTK_WINDOW_GET_PRIVATE (window);
2392 return priv->opacity;
2396 * gtk_window_set_type_hint:
2397 * @window: a #GtkWindow
2398 * @hint: the window type
2400 * By setting the type hint for the window, you allow the window
2401 * manager to decorate and handle the window in a way which is
2402 * suitable to the function of the window in your application.
2404 * This function should be called before the window becomes visible.
2406 * gtk_dialog_new_with_buttons() and other convenience functions in GTK+
2407 * will sometimes call gtk_window_set_type_hint() on your behalf.
2411 gtk_window_set_type_hint (GtkWindow *window,
2412 GdkWindowTypeHint hint)
2414 GtkWindowPrivate *priv;
2416 g_return_if_fail (GTK_IS_WINDOW (window));
2417 g_return_if_fail (!GTK_WIDGET_VISIBLE (window));
2419 priv = GTK_WINDOW_GET_PRIVATE (window);
2421 if (hint < GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU)
2422 window->type_hint = hint;
2424 window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
2426 priv->reset_type_hint = TRUE;
2427 priv->type_hint = hint;
2431 * gtk_window_get_type_hint:
2432 * @window: a #GtkWindow
2434 * Gets the type hint for this window. See gtk_window_set_type_hint().
2436 * Return value: the type hint for @window.
2439 gtk_window_get_type_hint (GtkWindow *window)
2441 GtkWindowPrivate *priv;
2443 g_return_val_if_fail (GTK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
2445 priv = GTK_WINDOW_GET_PRIVATE (window);
2447 return priv->type_hint;
2451 * gtk_window_set_skip_taskbar_hint:
2452 * @window: a #GtkWindow
2453 * @setting: %TRUE to keep this window from appearing in the task bar
2455 * Windows may set a hint asking the desktop environment not to display
2456 * the window in the task bar. This function sets this hint.
2461 gtk_window_set_skip_taskbar_hint (GtkWindow *window,
2464 GtkWindowPrivate *priv;
2466 g_return_if_fail (GTK_IS_WINDOW (window));
2468 priv = GTK_WINDOW_GET_PRIVATE (window);
2470 setting = setting != FALSE;
2472 if (priv->skips_taskbar != setting)
2474 priv->skips_taskbar = setting;
2475 if (GTK_WIDGET_REALIZED (window))
2476 gdk_window_set_skip_taskbar_hint (GTK_WIDGET (window)->window,
2477 priv->skips_taskbar);
2478 g_object_notify (G_OBJECT (window), "skip-taskbar-hint");
2483 * gtk_window_get_skip_taskbar_hint:
2484 * @window: a #GtkWindow
2486 * Gets the value set by gtk_window_set_skip_taskbar_hint()
2488 * Return value: %TRUE if window shouldn't be in taskbar
2493 gtk_window_get_skip_taskbar_hint (GtkWindow *window)
2495 GtkWindowPrivate *priv;
2497 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
2499 priv = GTK_WINDOW_GET_PRIVATE (window);
2501 return priv->skips_taskbar;
2505 * gtk_window_set_skip_pager_hint:
2506 * @window: a #GtkWindow
2507 * @setting: %TRUE to keep this window from appearing in the pager
2509 * Windows may set a hint asking the desktop environment not to display
2510 * the window in the pager. This function sets this hint.
2511 * (A "pager" is any desktop navigation tool such as a workspace
2512 * switcher that displays a thumbnail representation of the windows
2518 gtk_window_set_skip_pager_hint (GtkWindow *window,
2521 GtkWindowPrivate *priv;
2523 g_return_if_fail (GTK_IS_WINDOW (window));
2525 priv = GTK_WINDOW_GET_PRIVATE (window);
2527 setting = setting != FALSE;
2529 if (priv->skips_pager != setting)
2531 priv->skips_pager = setting;
2532 if (GTK_WIDGET_REALIZED (window))
2533 gdk_window_set_skip_pager_hint (GTK_WIDGET (window)->window,
2535 g_object_notify (G_OBJECT (window), "skip-pager-hint");
2540 * gtk_window_get_skip_pager_hint:
2541 * @window: a #GtkWindow
2543 * Gets the value set by gtk_window_set_skip_pager_hint().
2545 * Return value: %TRUE if window shouldn't be in pager
2550 gtk_window_get_skip_pager_hint (GtkWindow *window)
2552 GtkWindowPrivate *priv;
2554 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
2556 priv = GTK_WINDOW_GET_PRIVATE (window);
2558 return priv->skips_pager;
2562 * gtk_window_set_urgency_hint:
2563 * @window: a #GtkWindow
2564 * @setting: %TRUE to mark this window as urgent
2566 * Windows may set a hint asking the desktop environment to draw
2567 * the users attention to the window. This function sets this hint.
2572 gtk_window_set_urgency_hint (GtkWindow *window,
2575 GtkWindowPrivate *priv;
2577 g_return_if_fail (GTK_IS_WINDOW (window));
2579 priv = GTK_WINDOW_GET_PRIVATE (window);
2581 setting = setting != FALSE;
2583 if (priv->urgent != setting)
2585 priv->urgent = setting;
2586 if (GTK_WIDGET_REALIZED (window))
2587 gdk_window_set_urgency_hint (GTK_WIDGET (window)->window,
2589 g_object_notify (G_OBJECT (window), "urgency-hint");
2594 * gtk_window_get_urgency_hint:
2595 * @window: a #GtkWindow
2597 * Gets the value set by gtk_window_set_urgency_hint()
2599 * Return value: %TRUE if window is urgent
2604 gtk_window_get_urgency_hint (GtkWindow *window)
2606 GtkWindowPrivate *priv;
2608 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
2610 priv = GTK_WINDOW_GET_PRIVATE (window);
2612 return priv->urgent;
2616 * gtk_window_set_accept_focus:
2617 * @window: a #GtkWindow
2618 * @setting: %TRUE to let this window receive input focus
2620 * Windows may set a hint asking the desktop environment not to receive
2621 * the input focus. This function sets this hint.
2626 gtk_window_set_accept_focus (GtkWindow *window,
2629 GtkWindowPrivate *priv;
2631 g_return_if_fail (GTK_IS_WINDOW (window));
2633 priv = GTK_WINDOW_GET_PRIVATE (window);
2635 setting = setting != FALSE;
2637 if (priv->accept_focus != setting)
2639 priv->accept_focus = setting;
2640 if (GTK_WIDGET_REALIZED (window))
2641 gdk_window_set_accept_focus (GTK_WIDGET (window)->window,
2642 priv->accept_focus);
2643 g_object_notify (G_OBJECT (window), "accept-focus");
2648 * gtk_window_get_accept_focus:
2649 * @window: a #GtkWindow
2651 * Gets the value set by gtk_window_set_accept_focus().
2653 * Return value: %TRUE if window should receive the input focus
2658 gtk_window_get_accept_focus (GtkWindow *window)
2660 GtkWindowPrivate *priv;
2662 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
2664 priv = GTK_WINDOW_GET_PRIVATE (window);
2666 return priv->accept_focus;
2670 * gtk_window_set_focus_on_map:
2671 * @window: a #GtkWindow
2672 * @setting: %TRUE to let this window receive input focus on map
2674 * Windows may set a hint asking the desktop environment not to receive
2675 * the input focus when the window is mapped. This function sets this
2681 gtk_window_set_focus_on_map (GtkWindow *window,
2684 GtkWindowPrivate *priv;
2686 g_return_if_fail (GTK_IS_WINDOW (window));
2688 priv = GTK_WINDOW_GET_PRIVATE (window);
2690 setting = setting != FALSE;
2692 if (priv->focus_on_map != setting)
2694 priv->focus_on_map = setting;
2695 if (GTK_WIDGET_REALIZED (window))
2696 gdk_window_set_focus_on_map (GTK_WIDGET (window)->window,
2697 priv->focus_on_map);
2698 g_object_notify (G_OBJECT (window), "focus-on-map");
2703 * gtk_window_get_focus_on_map:
2704 * @window: a #GtkWindow
2706 * Gets the value set by gtk_window_set_focus_on_map().
2708 * Return value: %TRUE if window should receive the input focus when
2714 gtk_window_get_focus_on_map (GtkWindow *window)
2716 GtkWindowPrivate *priv;
2718 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
2720 priv = GTK_WINDOW_GET_PRIVATE (window);
2722 return priv->focus_on_map;
2726 * gtk_window_set_destroy_with_parent:
2727 * @window: a #GtkWindow
2728 * @setting: whether to destroy @window with its transient parent
2730 * If @setting is %TRUE, then destroying the transient parent of @window
2731 * will also destroy @window itself. This is useful for dialogs that
2732 * shouldn't persist beyond the lifetime of the main window they're
2733 * associated with, for example.
2736 gtk_window_set_destroy_with_parent (GtkWindow *window,
2739 g_return_if_fail (GTK_IS_WINDOW (window));
2741 if (window->destroy_with_parent == (setting != FALSE))
2744 if (window->destroy_with_parent)
2746 disconnect_parent_destroyed (window);
2750 connect_parent_destroyed (window);
2753 window->destroy_with_parent = setting;
2755 g_object_notify (G_OBJECT (window), "destroy-with-parent");
2759 * gtk_window_get_destroy_with_parent:
2760 * @window: a #GtkWindow
2762 * Returns whether the window will be destroyed with its transient parent. See
2763 * gtk_window_set_destroy_with_parent ().
2765 * Return value: %TRUE if the window will be destroyed with its transient parent.
2768 gtk_window_get_destroy_with_parent (GtkWindow *window)
2770 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
2772 return window->destroy_with_parent;
2775 static GtkWindowGeometryInfo*
2776 gtk_window_get_geometry_info (GtkWindow *window,
2779 GtkWindowGeometryInfo *info;
2781 info = window->geometry_info;
2782 if (!info && create)
2784 info = g_new0 (GtkWindowGeometryInfo, 1);
2786 info->default_width = -1;
2787 info->default_height = -1;
2788 info->resize_width = -1;
2789 info->resize_height = -1;
2790 info->initial_x = 0;
2791 info->initial_y = 0;
2792 info->initial_pos_set = FALSE;
2793 info->default_is_geometry = FALSE;
2794 info->position_constraints_changed = FALSE;
2795 info->last.configure_request.x = 0;
2796 info->last.configure_request.y = 0;
2797 info->last.configure_request.width = -1;
2798 info->last.configure_request.height = -1;
2799 info->widget = NULL;
2801 window->geometry_info = info;
2808 * gtk_window_set_geometry_hints:
2809 * @window: a #GtkWindow
2810 * @geometry_widget: widget the geometry hints will be applied to
2811 * @geometry: struct containing geometry information
2812 * @geom_mask: mask indicating which struct fields should be paid attention to
2814 * This function sets up hints about how a window can be resized by
2815 * the user. You can set a minimum and maximum size; allowed resize
2816 * increments (e.g. for xterm, you can only resize by the size of a
2817 * character); aspect ratios; and more. See the #GdkGeometry struct.
2821 gtk_window_set_geometry_hints (GtkWindow *window,
2822 GtkWidget *geometry_widget,
2823 GdkGeometry *geometry,
2824 GdkWindowHints geom_mask)
2826 GtkWindowGeometryInfo *info;
2828 g_return_if_fail (GTK_IS_WINDOW (window));
2829 g_return_if_fail (geometry_widget == NULL || GTK_IS_WIDGET (geometry_widget));
2831 info = gtk_window_get_geometry_info (window, TRUE);
2834 g_signal_handlers_disconnect_by_func (info->widget,
2835 gtk_widget_destroyed,
2838 info->widget = geometry_widget;
2840 g_signal_connect (geometry_widget, "destroy",
2841 G_CALLBACK (gtk_widget_destroyed),
2845 info->geometry = *geometry;
2847 /* We store gravity in window->gravity not in the hints. */
2848 info->mask = geom_mask & ~(GDK_HINT_WIN_GRAVITY);
2850 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2852 gtk_window_set_gravity (window, geometry->win_gravity);
2855 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
2859 * gtk_window_set_decorated:
2860 * @window: a #GtkWindow
2861 * @setting: %TRUE to decorate the window
2863 * By default, windows are decorated with a title bar, resize
2864 * controls, etc. Some <link linkend="gtk-X11-arch">window
2865 * managers</link> allow GTK+ to disable these decorations, creating a
2866 * borderless window. If you set the decorated property to %FALSE
2867 * using this function, GTK+ will do its best to convince the window
2868 * manager not to decorate the window. Depending on the system, this
2869 * function may not have any effect when called on a window that is
2870 * already visible, so you should call it before calling gtk_window_show().
2872 * On Windows, this function always works, since there's no window manager
2877 gtk_window_set_decorated (GtkWindow *window,
2880 g_return_if_fail (GTK_IS_WINDOW (window));
2882 setting = setting != FALSE;
2884 if (setting == window->decorated)
2887 window->decorated = setting;
2889 if (GTK_WIDGET (window)->window)
2891 if (window->decorated)
2892 gdk_window_set_decorations (GTK_WIDGET (window)->window,
2895 gdk_window_set_decorations (GTK_WIDGET (window)->window,
2899 g_object_notify (G_OBJECT (window), "decorated");
2903 * gtk_window_get_decorated:
2904 * @window: a #GtkWindow
2906 * Returns whether the window has been set to have decorations
2907 * such as a title bar via gtk_window_set_decorated().
2909 * Return value: %TRUE if the window has been set to have decorations
2912 gtk_window_get_decorated (GtkWindow *window)
2914 g_return_val_if_fail (GTK_IS_WINDOW (window), TRUE);
2916 return window->decorated;
2920 * gtk_window_set_deletable:
2921 * @window: a #GtkWindow
2922 * @setting: %TRUE to decorate the window as deletable
2924 * By default, windows have a close button in the window frame. Some
2925 * <link linkend="gtk-X11-arch">window managers</link> allow GTK+ to
2926 * disable this button. If you set the deletable property to %FALSE
2927 * using this function, GTK+ will do its best to convince the window
2928 * manager not to show a close button. Depending on the system, this
2929 * function may not have any effect when called on a window that is
2930 * already visible, so you should call it before calling gtk_window_show().
2932 * On Windows, this function always works, since there's no window manager
2938 gtk_window_set_deletable (GtkWindow *window,
2941 GtkWindowPrivate *priv;
2943 g_return_if_fail (GTK_IS_WINDOW (window));
2945 priv = GTK_WINDOW_GET_PRIVATE (window);
2947 setting = setting != FALSE;
2949 if (setting == priv->deletable)
2952 priv->deletable = setting;
2954 if (GTK_WIDGET (window)->window)
2956 if (priv->deletable)
2957 gdk_window_set_functions (GTK_WIDGET (window)->window,
2960 gdk_window_set_functions (GTK_WIDGET (window)->window,
2961 GDK_FUNC_ALL | GDK_FUNC_CLOSE);
2964 g_object_notify (G_OBJECT (window), "deletable");
2968 * gtk_window_get_deletable:
2969 * @window: a #GtkWindow
2971 * Returns whether the window has been set to have a close button
2972 * via gtk_window_set_deletable().
2974 * Return value: %TRUE if the window has been set to have a close button
2979 gtk_window_get_deletable (GtkWindow *window)
2981 GtkWindowPrivate *priv;
2983 g_return_val_if_fail (GTK_IS_WINDOW (window), TRUE);
2985 priv = GTK_WINDOW_GET_PRIVATE (window);
2987 return priv->deletable;
2990 static GtkWindowIconInfo*
2991 get_icon_info (GtkWindow *window)
2993 return g_object_get_qdata (G_OBJECT (window), quark_gtk_window_icon_info);
2997 free_icon_info (GtkWindowIconInfo *info)
2999 g_free (info->icon_name);
3000 g_slice_free (GtkWindowIconInfo, info);
3004 static GtkWindowIconInfo*
3005 ensure_icon_info (GtkWindow *window)
3007 GtkWindowIconInfo *info;
3009 info = get_icon_info (window);
3013 info = g_slice_new0 (GtkWindowIconInfo);
3014 g_object_set_qdata_full (G_OBJECT (window),
3015 quark_gtk_window_icon_info,
3017 (GDestroyNotify)free_icon_info);
3029 static ScreenIconInfo *
3030 get_screen_icon_info (GdkScreen *screen)
3032 ScreenIconInfo *info = g_object_get_qdata (G_OBJECT (screen),
3033 quark_gtk_window_default_icon_pixmap);
3036 info = g_slice_new0 (ScreenIconInfo);
3037 g_object_set_qdata (G_OBJECT (screen),
3038 quark_gtk_window_default_icon_pixmap, info);
3041 if (info->serial != default_icon_serial)
3045 g_object_remove_weak_pointer (G_OBJECT (info->pixmap), (gpointer*)&info->pixmap);
3046 info->pixmap = NULL;
3051 g_object_remove_weak_pointer (G_OBJECT (info->mask), (gpointer*)&info->mask);
3055 info->serial = default_icon_serial;
3062 get_pixmap_and_mask (GdkWindow *window,
3063 GtkWindowIconInfo *parent_info,
3064 gboolean is_default_list,
3066 GdkPixmap **pmap_return,
3067 GdkBitmap **mask_return)
3069 GdkScreen *screen = gdk_drawable_get_screen (window);
3070 ScreenIconInfo *default_icon_info = get_screen_icon_info (screen);
3071 GdkPixbuf *best_icon;
3075 *pmap_return = NULL;
3076 *mask_return = NULL;
3078 if (is_default_list &&
3079 default_icon_info->pixmap != NULL)
3081 /* Use shared icon pixmap for all windows on this screen.
3083 if (default_icon_info->pixmap)
3084 g_object_ref (default_icon_info->pixmap);
3085 if (default_icon_info->mask)
3086 g_object_ref (default_icon_info->mask);
3088 *pmap_return = default_icon_info->pixmap;
3089 *mask_return = default_icon_info->mask;
3091 else if (parent_info && parent_info->icon_pixmap)
3093 if (parent_info->icon_pixmap)
3094 g_object_ref (parent_info->icon_pixmap);
3095 if (parent_info->icon_mask)
3096 g_object_ref (parent_info->icon_mask);
3098 *pmap_return = parent_info->icon_pixmap;
3099 *mask_return = parent_info->icon_mask;
3103 #define IDEAL_SIZE 48
3105 best_size = G_MAXINT;
3107 tmp_list = icon_list;
3108 while (tmp_list != NULL)
3110 GdkPixbuf *pixbuf = tmp_list->data;
3113 /* average width and height - if someone passes in a rectangular
3114 * icon they deserve what they get.
3116 this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
3119 if (best_icon == NULL)
3126 /* icon is better if it's 32 pixels or larger, and closer to
3127 * the ideal size than the current best.
3130 (ABS (best_size - IDEAL_SIZE) <
3131 ABS (this - IDEAL_SIZE)))
3138 tmp_list = tmp_list->next;
3142 gdk_pixbuf_render_pixmap_and_mask_for_colormap (best_icon,
3143 gdk_screen_get_system_colormap (screen),
3148 /* Save pmap/mask for others to use if appropriate */
3151 parent_info->icon_pixmap = *pmap_return;
3152 parent_info->icon_mask = *mask_return;
3154 if (parent_info->icon_pixmap)
3155 g_object_ref (parent_info->icon_pixmap);
3156 if (parent_info->icon_mask)
3157 g_object_ref (parent_info->icon_mask);
3159 else if (is_default_list)
3161 default_icon_info->pixmap = *pmap_return;
3162 default_icon_info->mask = *mask_return;
3164 if (default_icon_info->pixmap)
3165 g_object_add_weak_pointer (G_OBJECT (default_icon_info->pixmap),
3166 (gpointer*)&default_icon_info->pixmap);
3167 if (default_icon_info->mask)
3168 g_object_add_weak_pointer (G_OBJECT (default_icon_info->mask),
3169 (gpointer*)&default_icon_info->mask);
3175 icon_list_from_theme (GtkWidget *widget,
3180 GtkIconTheme *icon_theme;
3185 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
3187 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, name);
3190 for (i = 0; sizes[i]; i++)
3193 * We need an EWMH extension to handle scalable icons
3194 * by passing their name to the WM. For now just use a
3198 icon = gtk_icon_theme_load_icon (icon_theme, name,
3201 icon = gtk_icon_theme_load_icon (icon_theme, name,
3204 list = g_list_append (list, icon);
3214 gtk_window_realize_icon (GtkWindow *window)
3217 GtkWindowIconInfo *info;
3220 widget = GTK_WIDGET (window);
3222 g_return_if_fail (widget->window != NULL);
3224 /* no point setting an icon on override-redirect */
3225 if (window->type == GTK_WINDOW_POPUP)
3230 info = ensure_icon_info (window);
3235 g_return_if_fail (info->icon_pixmap == NULL);
3236 g_return_if_fail (info->icon_mask == NULL);
3238 info->using_default_icon = FALSE;
3239 info->using_parent_icon = FALSE;
3240 info->using_themed_icon = FALSE;
3242 icon_list = info->icon_list;
3244 /* Look up themed icon */
3245 if (icon_list == NULL && info->icon_name)
3247 icon_list = icon_list_from_theme (widget, info->icon_name);
3249 info->using_themed_icon = TRUE;
3252 /* Inherit from transient parent */
3253 if (icon_list == NULL && window->transient_parent)
3255 icon_list = ensure_icon_info (window->transient_parent)->icon_list;
3257 info->using_parent_icon = TRUE;
3260 /* Inherit from default */
3261 if (icon_list == NULL)
3263 icon_list = default_icon_list;
3265 info->using_default_icon = TRUE;
3268 /* Look up themed icon */
3269 if (icon_list == NULL && default_icon_name)
3271 icon_list = icon_list_from_theme (widget, default_icon_name);
3272 info->using_default_icon = TRUE;
3273 info->using_themed_icon = TRUE;
3276 gdk_window_set_icon_list (widget->window, icon_list);
3278 get_pixmap_and_mask (widget->window,
3279 info->using_parent_icon ? ensure_icon_info (window->transient_parent) : NULL,
3280 info->using_default_icon,
3285 /* This is a slight ICCCM violation since it's a color pixmap not
3286 * a bitmap, but everyone does it.
3288 gdk_window_set_icon (widget->window,
3293 info->realized = TRUE;
3295 if (info->using_themed_icon)
3297 GtkIconTheme *icon_theme;
3299 g_list_foreach (icon_list, (GFunc) g_object_unref, NULL);
3300 g_list_free (icon_list);
3302 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)));
3303 g_signal_connect (icon_theme, "changed",
3304 G_CALLBACK (update_themed_icon), window);
3309 gtk_window_unrealize_icon (GtkWindow *window)
3311 GtkWindowIconInfo *info;
3313 info = get_icon_info (window);
3318 if (info->icon_pixmap)
3319 g_object_unref (info->icon_pixmap);
3321 if (info->icon_mask)
3322 g_object_unref (info->icon_mask);
3324 info->icon_pixmap = NULL;
3325 info->icon_mask = NULL;
3327 if (info->using_themed_icon)
3329 GtkIconTheme *icon_theme;
3331 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)));
3333 g_signal_handlers_disconnect_by_func (icon_theme, update_themed_icon, window);
3336 /* We don't clear the properties on the window, just figure the
3337 * window is going away.
3340 info->realized = FALSE;
3345 * gtk_window_set_icon_list:
3346 * @window: a #GtkWindow
3347 * @list: list of #GdkPixbuf
3349 * Sets up the icon representing a #GtkWindow. The icon is used when
3350 * the window is minimized (also known as iconified). Some window
3351 * managers or desktop environments may also place it in the window
3352 * frame, or display it in other contexts.
3354 * gtk_window_set_icon_list() allows you to pass in the same icon in
3355 * several hand-drawn sizes. The list should contain the natural sizes
3356 * your icon is available in; that is, don't scale the image before
3357 * passing it to GTK+. Scaling is postponed until the last minute,
3358 * when the desired final size is known, to allow best quality.
3360 * By passing several sizes, you may improve the final image quality
3361 * of the icon, by reducing or eliminating automatic image scaling.
3363 * Recommended sizes to provide: 16x16, 32x32, 48x48 at minimum, and
3364 * larger images (64x64, 128x128) if you have them.
3366 * See also gtk_window_set_default_icon_list() to set the icon
3367 * for all windows in your application in one go.
3369 * Note that transient windows (those who have been set transient for another
3370 * window using gtk_window_set_transient_for()) will inherit their
3371 * icon from their transient parent. So there's no need to explicitly
3372 * set the icon on transient windows.
3375 gtk_window_set_icon_list (GtkWindow *window,
3378 GtkWindowIconInfo *info;
3380 g_return_if_fail (GTK_IS_WINDOW (window));
3382 info = ensure_icon_info (window);
3384 if (info->icon_list == list) /* check for NULL mostly */
3387 g_list_foreach (list,
3388 (GFunc) g_object_ref, NULL);
3390 g_list_foreach (info->icon_list,
3391 (GFunc) g_object_unref, NULL);
3393 g_list_free (info->icon_list);
3395 info->icon_list = g_list_copy (list);
3397 g_object_notify (G_OBJECT (window), "icon");
3399 gtk_window_unrealize_icon (window);
3401 if (GTK_WIDGET_REALIZED (window))
3402 gtk_window_realize_icon (window);
3404 /* We could try to update our transient children, but I don't think
3405 * it's really worth it. If we did it, the best way would probably
3406 * be to have children connect to notify::icon-list
3411 * gtk_window_get_icon_list:
3412 * @window: a #GtkWindow
3414 * Retrieves the list of icons set by gtk_window_set_icon_list().
3415 * The list is copied, but the reference count on each
3416 * member won't be incremented.
3418 * Return value: copy of window's icon list
3421 gtk_window_get_icon_list (GtkWindow *window)
3423 GtkWindowIconInfo *info;
3425 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
3427 info = get_icon_info (window);
3430 return g_list_copy (info->icon_list);
3436 * gtk_window_set_icon:
3437 * @window: a #GtkWindow
3438 * @icon: icon image, or %NULL
3440 * Sets up the icon representing a #GtkWindow. This icon is used when
3441 * the window is minimized (also known as iconified). Some window
3442 * managers or desktop environments may also place it in the window
3443 * frame, or display it in other contexts.
3445 * The icon should be provided in whatever size it was naturally
3446 * drawn; that is, don't scale the image before passing it to
3447 * GTK+. Scaling is postponed until the last minute, when the desired
3448 * final size is known, to allow best quality.
3450 * If you have your icon hand-drawn in multiple sizes, use
3451 * gtk_window_set_icon_list(). Then the best size will be used.
3453 * This function is equivalent to calling gtk_window_set_icon_list()
3454 * with a 1-element list.
3456 * See also gtk_window_set_default_icon_list() to set the icon
3457 * for all windows in your application in one go.
3460 gtk_window_set_icon (GtkWindow *window,
3465 g_return_if_fail (GTK_IS_WINDOW (window));
3466 g_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon));
3471 list = g_list_append (list, icon);
3473 gtk_window_set_icon_list (window, list);
3479 update_themed_icon (GtkIconTheme *icon_theme,
3482 g_object_notify (G_OBJECT (window), "icon");
3484 gtk_window_unrealize_icon (window);
3486 if (GTK_WIDGET_REALIZED (window))
3487 gtk_window_realize_icon (window);
3491 * gtk_window_set_icon_name:
3492 * @window: a #GtkWindow
3493 * @name: the name of the themed icon
3495 * Sets the icon for the window from a named themed icon. See
3496 * the docs for #GtkIconTheme for more details.
3498 * Note that this has nothing to do with the WM_ICON_NAME
3499 * property which is mentioned in the ICCCM.
3504 gtk_window_set_icon_name (GtkWindow *window,
3507 GtkWindowIconInfo *info;
3510 g_return_if_fail (GTK_IS_WINDOW (window));
3512 info = ensure_icon_info (window);
3514 if (g_strcmp0 (info->icon_name, name) == 0)
3517 tmp = info->icon_name;
3518 info->icon_name = g_strdup (name);
3521 g_list_foreach (info->icon_list, (GFunc) g_object_unref, NULL);
3522 g_list_free (info->icon_list);
3523 info->icon_list = NULL;
3525 update_themed_icon (NULL, window);
3527 g_object_notify (G_OBJECT (window), "icon-name");
3531 * gtk_window_get_icon_name:
3532 * @window: a #GtkWindow
3534 * Returns the name of the themed icon for the window,
3535 * see gtk_window_set_icon_name().
3537 * Returns: the icon name or %NULL if the window has
3542 G_CONST_RETURN gchar *
3543 gtk_window_get_icon_name (GtkWindow *window)
3545 GtkWindowIconInfo *info;
3547 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
3549 info = ensure_icon_info (window);
3551 return info->icon_name;
3555 * gtk_window_get_icon:
3556 * @window: a #GtkWindow
3558 * Gets the value set by gtk_window_set_icon() (or if you've
3559 * called gtk_window_set_icon_list(), gets the first icon in
3562 * Return value: icon for window
3565 gtk_window_get_icon (GtkWindow *window)
3567 GtkWindowIconInfo *info;
3569 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
3571 info = get_icon_info (window);
3572 if (info && info->icon_list)
3573 return GDK_PIXBUF (info->icon_list->data);
3578 /* Load pixbuf, printing warning on failure if error == NULL
3581 load_pixbuf_verbosely (const char *filename,
3584 GError *local_err = NULL;
3587 pixbuf = gdk_pixbuf_new_from_file (filename, &local_err);
3595 g_warning ("Error loading icon from file '%s':\n\t%s",
3596 filename, local_err->message);
3597 g_error_free (local_err);
3605 * gtk_window_set_icon_from_file:
3606 * @window: a #GtkWindow
3607 * @filename: location of icon file
3608 * @err: location to store error, or %NULL.
3610 * Sets the icon for @window.
3611 * Warns on failure if @err is %NULL.
3613 * This function is equivalent to calling gtk_window_set_icon()
3614 * with a pixbuf created by loading the image from @filename.
3616 * Returns: %TRUE if setting the icon succeeded.
3621 gtk_window_set_icon_from_file (GtkWindow *window,
3622 const gchar *filename,
3625 GdkPixbuf *pixbuf = load_pixbuf_verbosely (filename, err);
3629 gtk_window_set_icon (window, pixbuf);
3630 g_object_unref (pixbuf);
3639 * gtk_window_set_default_icon_list:
3640 * @list: a list of #GdkPixbuf
3642 * Sets an icon list to be used as fallback for windows that haven't
3643 * had gtk_window_set_icon_list() called on them to set up a
3644 * window-specific icon list. This function allows you to set up the
3645 * icon for all windows in your app at once.
3647 * See gtk_window_set_icon_list() for more details.
3651 gtk_window_set_default_icon_list (GList *list)
3655 if (list == default_icon_list)
3658 /* Update serial so we don't used cached pixmaps/masks
3660 default_icon_serial++;
3662 g_list_foreach (list,
3663 (GFunc) g_object_ref, NULL);
3665 g_list_foreach (default_icon_list,
3666 (GFunc) g_object_unref, NULL);
3668 g_list_free (default_icon_list);
3670 default_icon_list = g_list_copy (list);
3672 /* Update all toplevels */
3673 toplevels = gtk_window_list_toplevels ();
3674 tmp_list = toplevels;
3675 while (tmp_list != NULL)
3677 GtkWindowIconInfo *info;
3678 GtkWindow *w = tmp_list->data;
3680 info = get_icon_info (w);
3681 if (info && info->using_default_icon)
3683 gtk_window_unrealize_icon (w);
3684 if (GTK_WIDGET_REALIZED (w))
3685 gtk_window_realize_icon (w);
3688 tmp_list = tmp_list->next;
3690 g_list_free (toplevels);
3694 * gtk_window_set_default_icon:
3697 * Sets an icon to be used as fallback for windows that haven't
3698 * had gtk_window_set_icon() called on them from a pixbuf.
3703 gtk_window_set_default_icon (GdkPixbuf *icon)
3707 g_return_if_fail (GDK_IS_PIXBUF (icon));
3709 list = g_list_prepend (NULL, icon);
3710 gtk_window_set_default_icon_list (list);
3715 * gtk_window_set_default_icon_name:
3716 * @name: the name of the themed icon
3718 * Sets an icon to be used as fallback for windows that haven't
3719 * had gtk_window_set_icon_list() called on them from a named
3720 * themed icon, see gtk_window_set_icon_name().
3725 gtk_window_set_default_icon_name (const gchar *name)
3730 /* Update serial so we don't used cached pixmaps/masks
3732 default_icon_serial++;
3734 g_free (default_icon_name);
3735 default_icon_name = g_strdup (name);
3737 g_list_foreach (default_icon_list,
3738 (GFunc) g_object_unref, NULL);
3740 g_list_free (default_icon_list);
3741 default_icon_list = NULL;
3743 /* Update all toplevels */
3744 toplevels = gtk_window_list_toplevels ();
3745 tmp_list = toplevels;
3746 while (tmp_list != NULL)
3748 GtkWindowIconInfo *info;
3749 GtkWindow *w = tmp_list->data;
3751 info = get_icon_info (w);
3752 if (info && info->using_default_icon && info->using_themed_icon)
3754 gtk_window_unrealize_icon (w);
3755 if (GTK_WIDGET_REALIZED (w))
3756 gtk_window_realize_icon (w);
3759 tmp_list = tmp_list->next;
3761 g_list_free (toplevels);
3765 * gtk_window_get_default_icon_name:
3767 * Returns the fallback icon name for windows that has been set
3768 * with gtk_window_set_default_icon_name(). The returned
3769 * string is owned by GTK+ and should not be modified. It
3770 * is only valid until the next call to
3771 * gtk_window_set_default_icon_name().
3773 * Returns: the fallback icon name for windows
3778 gtk_window_get_default_icon_name (void)
3780 return default_icon_name;
3784 * gtk_window_set_default_icon_from_file:
3785 * @filename: location of icon file
3786 * @err: location to store error, or %NULL.
3788 * Sets an icon to be used as fallback for windows that haven't
3789 * had gtk_window_set_icon_list() called on them from a file
3790 * on disk. Warns on failure if @err is %NULL.
3792 * Returns: %TRUE if setting the icon succeeded.
3797 gtk_window_set_default_icon_from_file (const gchar *filename,
3800 GdkPixbuf *pixbuf = load_pixbuf_verbosely (filename, err);
3804 gtk_window_set_default_icon (pixbuf);
3805 g_object_unref (pixbuf);
3814 * gtk_window_get_default_icon_list:
3816 * Gets the value set by gtk_window_set_default_icon_list().
3817 * The list is a copy and should be freed with g_list_free(),
3818 * but the pixbufs in the list have not had their reference count
3821 * Return value: copy of default icon list
3824 gtk_window_get_default_icon_list (void)
3826 return g_list_copy (default_icon_list);
3830 gtk_window_set_default_size_internal (GtkWindow *window,
3831 gboolean change_width,
3833 gboolean change_height,
3835 gboolean is_geometry)
3837 GtkWindowGeometryInfo *info;
3839 g_return_if_fail (change_width == FALSE || width >= -1);
3840 g_return_if_fail (change_height == FALSE || height >= -1);
3842 info = gtk_window_get_geometry_info (window, TRUE);
3844 g_object_freeze_notify (G_OBJECT (window));
3846 info->default_is_geometry = is_geometry != FALSE;
3856 info->default_width = width;
3858 g_object_notify (G_OBJECT (window), "default-width");
3869 info->default_height = height;
3871 g_object_notify (G_OBJECT (window), "default-height");
3874 g_object_thaw_notify (G_OBJECT (window));
3876 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
3880 * gtk_window_set_default_size:
3881 * @window: a #GtkWindow
3882 * @width: width in pixels, or -1 to unset the default width
3883 * @height: height in pixels, or -1 to unset the default height
3885 * Sets the default size of a window. If the window's "natural" size
3886 * (its size request) is larger than the default, the default will be
3887 * ignored. More generally, if the default size does not obey the
3888 * geometry hints for the window (gtk_window_set_geometry_hints() can
3889 * be used to set these explicitly), the default size will be clamped
3890 * to the nearest permitted size.
3892 * Unlike gtk_widget_set_size_request(), which sets a size request for
3893 * a widget and thus would keep users from shrinking the window, this
3894 * function only sets the initial size, just as if the user had
3895 * resized the window themselves. Users can still shrink the window
3896 * again as they normally would. Setting a default size of -1 means to
3897 * use the "natural" default size (the size request of the window).
3899 * For more control over a window's initial size and how resizing works,
3900 * investigate gtk_window_set_geometry_hints().
3902 * For some uses, gtk_window_resize() is a more appropriate function.
3903 * gtk_window_resize() changes the current size of the window, rather
3904 * than the size to be used on initial display. gtk_window_resize() always
3905 * affects the window itself, not the geometry widget.
3907 * The default size of a window only affects the first time a window is
3908 * shown; if a window is hidden and re-shown, it will remember the size
3909 * it had prior to hiding, rather than using the default size.
3911 * Windows can't actually be 0x0 in size, they must be at least 1x1, but
3912 * passing 0 for @width and @height is OK, resulting in a 1x1 default size.
3915 gtk_window_set_default_size (GtkWindow *window,
3919 g_return_if_fail (GTK_IS_WINDOW (window));
3920 g_return_if_fail (width >= -1);
3921 g_return_if_fail (height >= -1);
3923 gtk_window_set_default_size_internal (window, TRUE, width, TRUE, height, FALSE);
3927 * gtk_window_get_default_size:
3928 * @window: a #GtkWindow
3929 * @width: location to store the default width, or %NULL
3930 * @height: location to store the default height, or %NULL
3932 * Gets the default size of the window. A value of -1 for the width or
3933 * height indicates that a default size has not been explicitly set
3934 * for that dimension, so the "natural" size of the window will be
3939 gtk_window_get_default_size (GtkWindow *window,
3943 GtkWindowGeometryInfo *info;
3945 g_return_if_fail (GTK_IS_WINDOW (window));
3947 info = gtk_window_get_geometry_info (window, FALSE);
3950 *width = info ? info->default_width : -1;
3953 *height = info ? info->default_height : -1;
3957 * gtk_window_resize:
3958 * @window: a #GtkWindow
3959 * @width: width in pixels to resize the window to
3960 * @height: height in pixels to resize the window to
3962 * Resizes the window as if the user had done so, obeying geometry
3963 * constraints. The default geometry constraint is that windows may
3964 * not be smaller than their size request; to override this
3965 * constraint, call gtk_widget_set_size_request() to set the window's
3966 * request to a smaller value.
3968 * If gtk_window_resize() is called before showing a window for the
3969 * first time, it overrides any default size set with
3970 * gtk_window_set_default_size().
3972 * Windows may not be resized smaller than 1 by 1 pixels.
3976 gtk_window_resize (GtkWindow *window,
3980 GtkWindowGeometryInfo *info;
3982 g_return_if_fail (GTK_IS_WINDOW (window));
3983 g_return_if_fail (width > 0);
3984 g_return_if_fail (height > 0);
3986 info = gtk_window_get_geometry_info (window, TRUE);
3988 info->resize_width = width;
3989 info->resize_height = height;
3991 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
3995 * gtk_window_get_size:
3996 * @window: a #GtkWindow
3997 * @width: return location for width, or %NULL
3998 * @height: return location for height, or %NULL
4000 * Obtains the current size of @window. If @window is not onscreen,
4001 * it returns the size GTK+ will suggest to the <link
4002 * linkend="gtk-X11-arch">window manager</link> for the initial window
4003 * size (but this is not reliably the same as the size the window
4004 * manager will actually select). The size obtained by
4005 * gtk_window_get_size() is the last size received in a
4006 * #GdkEventConfigure, that is, GTK+ uses its locally-stored size,
4007 * rather than querying the X server for the size. As a result, if you
4008 * call gtk_window_resize() then immediately call
4009 * gtk_window_get_size(), the size won't have taken effect yet. After
4010 * the window manager processes the resize request, GTK+ receives
4011 * notification that the size has changed via a configure event, and
4012 * the size of the window gets updated.
4014 * Note 1: Nearly any use of this function creates a race condition,
4015 * because the size of the window may change between the time that you
4016 * get the size and the time that you perform some action assuming
4017 * that size is the current size. To avoid race conditions, connect to
4018 * "configure-event" on the window and adjust your size-dependent
4019 * state to match the size delivered in the #GdkEventConfigure.
4021 * Note 2: The returned size does <emphasis>not</emphasis> include the
4022 * size of the window manager decorations (aka the window frame or
4023 * border). Those are not drawn by GTK+ and GTK+ has no reliable
4024 * method of determining their size.
4026 * Note 3: If you are getting a window size in order to position
4027 * the window onscreen, there may be a better way. The preferred
4028 * way is to simply set the window's semantic type with
4029 * gtk_window_set_type_hint(), which allows the window manager to
4030 * e.g. center dialogs. Also, if you set the transient parent of
4031 * dialogs with gtk_window_set_transient_for() window managers
4032 * will often center the dialog over its parent window. It's
4033 * much preferred to let the window manager handle these
4034 * things rather than doing it yourself, because all apps will
4035 * behave consistently and according to user prefs if the window
4036 * manager handles it. Also, the window manager can take the size
4037 * of the window decorations/border into account, while your
4038 * application cannot.
4040 * In any case, if you insist on application-specified window
4041 * positioning, there's <emphasis>still</emphasis> a better way than
4042 * doing it yourself - gtk_window_set_position() will frequently
4043 * handle the details for you.
4047 gtk_window_get_size (GtkWindow *window,
4053 g_return_if_fail (GTK_IS_WINDOW (window));
4055 if (width == NULL && height == NULL)
4058 if (GTK_WIDGET_MAPPED (window))
4060 gdk_drawable_get_size (GTK_WIDGET (window)->window,
4065 GdkRectangle configure_request;
4067 gtk_window_compute_configure_request (window,
4071 w = configure_request.width;
4072 h = configure_request.height;
4083 * @window: a #GtkWindow
4084 * @x: X coordinate to move window to
4085 * @y: Y coordinate to move window to
4087 * Asks the <link linkend="gtk-X11-arch">window manager</link> to move
4088 * @window to the given position. Window managers are free to ignore
4089 * this; most window managers ignore requests for initial window
4090 * positions (instead using a user-defined placement algorithm) and
4091 * honor requests after the window has already been shown.
4093 * Note: the position is the position of the gravity-determined
4094 * reference point for the window. The gravity determines two things:
4095 * first, the location of the reference point in root window
4096 * coordinates; and second, which point on the window is positioned at
4097 * the reference point.
4099 * By default the gravity is #GDK_GRAVITY_NORTH_WEST, so the reference
4100 * point is simply the @x, @y supplied to gtk_window_move(). The
4101 * top-left corner of the window decorations (aka window frame or
4102 * border) will be placed at @x, @y. Therefore, to position a window
4103 * at the top left of the screen, you want to use the default gravity
4104 * (which is #GDK_GRAVITY_NORTH_WEST) and move the window to 0,0.
4106 * To position a window at the bottom right corner of the screen, you
4107 * would set #GDK_GRAVITY_SOUTH_EAST, which means that the reference
4108 * point is at @x + the window width and @y + the window height, and
4109 * the bottom-right corner of the window border will be placed at that
4110 * reference point. So, to place a window in the bottom right corner
4111 * you would first set gravity to south east, then write:
4112 * <literal>gtk_window_move (window, gdk_screen_width () - window_width,
4113 * gdk_screen_height () - window_height)</literal> (note that this
4114 * example does not take multi-head scenarios into account).
4116 * The Extended Window Manager Hints specification at <ulink
4117 * url="http://www.freedesktop.org/Standards/wm-spec">
4118 * http://www.freedesktop.org/Standards/wm-spec</ulink> has a
4119 * nice table of gravities in the "implementation notes" section.
4121 * The gtk_window_get_position() documentation may also be relevant.
4124 gtk_window_move (GtkWindow *window,
4128 GtkWindowGeometryInfo *info;
4131 g_return_if_fail (GTK_IS_WINDOW (window));
4133 widget = GTK_WIDGET (window);
4135 info = gtk_window_get_geometry_info (window, TRUE);
4137 if (GTK_WIDGET_MAPPED (window))
4139 /* we have now sent a request with this position
4140 * with currently-active constraints, so toggle flag.
4142 info->position_constraints_changed = FALSE;
4144 /* we only constrain if mapped - if not mapped,
4145 * then gtk_window_compute_configure_request()
4146 * will apply the constraints later, and we
4147 * don't want to lose information about
4148 * what position the user set before then.
4149 * i.e. if you do a move() then turn off POS_CENTER
4150 * then show the window, your move() will work.
4152 gtk_window_constrain_position (window,
4153 widget->allocation.width,
4154 widget->allocation.height,
4157 /* Note that this request doesn't go through our standard request
4158 * framework, e.g. doesn't increment configure_request_count,
4159 * doesn't set info->last, etc.; that's because
4160 * we don't save the info needed to arrive at this same request
4163 * To gtk_window_move_resize(), this will end up looking exactly
4164 * the same as the position being changed by the window
4168 /* FIXME are we handling gravity properly for framed windows? */
4170 gdk_window_move (window->frame,
4171 x - window->frame_left,
4172 y - window->frame_top);
4174 gdk_window_move (GTK_WIDGET (window)->window,
4179 /* Save this position to apply on mapping */
4180 info->initial_x = x;
4181 info->initial_y = y;
4182 info->initial_pos_set = TRUE;
4187 * gtk_window_get_position:
4188 * @window: a #GtkWindow
4189 * @root_x: return location for X coordinate of gravity-determined reference point
4190 * @root_y: return location for Y coordinate of gravity-determined reference point
4192 * This function returns the position you need to pass to
4193 * gtk_window_move() to keep @window in its current position. This
4194 * means that the meaning of the returned value varies with window
4195 * gravity. See gtk_window_move() for more details.
4197 * If you haven't changed the window gravity, its gravity will be
4198 * #GDK_GRAVITY_NORTH_WEST. This means that gtk_window_get_position()
4199 * gets the position of the top-left corner of the window manager
4200 * frame for the window. gtk_window_move() sets the position of this
4201 * same top-left corner.
4203 * gtk_window_get_position() is not 100% reliable because the X Window System
4204 * does not specify a way to obtain the geometry of the
4205 * decorations placed on a window by the window manager.
4206 * Thus GTK+ is using a "best guess" that works with most
4209 * Moreover, nearly all window managers are historically broken with
4210 * respect to their handling of window gravity. So moving a window to
4211 * its current position as returned by gtk_window_get_position() tends
4212 * to result in moving the window slightly. Window managers are
4213 * slowly getting better over time.
4215 * If a window has gravity #GDK_GRAVITY_STATIC the window manager
4216 * frame is not relevant, and thus gtk_window_get_position() will
4217 * always produce accurate results. However you can't use static
4218 * gravity to do things like place a window in a corner of the screen,
4219 * because static gravity ignores the window manager decorations.
4221 * If you are saving and restoring your application's window
4222 * positions, you should know that it's impossible for applications to
4223 * do this without getting it somewhat wrong because applications do
4224 * not have sufficient knowledge of window manager state. The Correct
4225 * Mechanism is to support the session management protocol (see the
4226 * "GnomeClient" object in the GNOME libraries for example) and allow
4227 * the window manager to save your window sizes and positions.
4232 gtk_window_get_position (GtkWindow *window,
4238 g_return_if_fail (GTK_IS_WINDOW (window));
4240 widget = GTK_WIDGET (window);
4242 if (window->gravity == GDK_GRAVITY_STATIC)
4244 if (GTK_WIDGET_MAPPED (widget))
4246 /* This does a server round-trip, which is sort of wrong;
4247 * but a server round-trip is inevitable for
4248 * gdk_window_get_frame_extents() in the usual
4249 * NorthWestGravity case below, so not sure what else to
4250 * do. We should likely be consistent about whether we get
4251 * the client-side info or the server-side info.
4253 gdk_window_get_origin (widget->window, root_x, root_y);
4257 GdkRectangle configure_request;
4259 gtk_window_compute_configure_request (window,
4263 *root_x = configure_request.x;
4264 *root_y = configure_request.y;
4269 GdkRectangle frame_extents;
4274 if (GTK_WIDGET_MAPPED (widget))
4277 gdk_window_get_frame_extents (window->frame, &frame_extents);
4279 gdk_window_get_frame_extents (widget->window, &frame_extents);
4280 x = frame_extents.x;
4281 y = frame_extents.y;
4282 gtk_window_get_size (window, &w, &h);
4286 /* We just say the frame has 0 size on all sides.
4287 * Not sure what else to do.
4289 gtk_window_compute_configure_request (window,
4292 x = frame_extents.x;
4293 y = frame_extents.y;
4294 w = frame_extents.width;
4295 h = frame_extents.height;
4298 switch (window->gravity)
4300 case GDK_GRAVITY_NORTH:
4301 case GDK_GRAVITY_CENTER:
4302 case GDK_GRAVITY_SOUTH:
4303 /* Find center of frame. */
4304 x += frame_extents.width / 2;
4305 /* Center client window on that point. */
4309 case GDK_GRAVITY_SOUTH_EAST:
4310 case GDK_GRAVITY_EAST:
4311 case GDK_GRAVITY_NORTH_EAST:
4312 /* Find right edge of frame */
4313 x += frame_extents.width;
4314 /* Align left edge of client at that point. */
4321 switch (window->gravity)
4323 case GDK_GRAVITY_WEST:
4324 case GDK_GRAVITY_CENTER:
4325 case GDK_GRAVITY_EAST:
4326 /* Find center of frame. */
4327 y += frame_extents.height / 2;
4328 /* Center client window there. */
4331 case GDK_GRAVITY_SOUTH_WEST:
4332 case GDK_GRAVITY_SOUTH:
4333 case GDK_GRAVITY_SOUTH_EAST:
4334 /* Find south edge of frame */
4335 y += frame_extents.height;
4336 /* Place bottom edge of client there */
4351 * gtk_window_reshow_with_initial_size:
4352 * @window: a #GtkWindow
4354 * Hides @window, then reshows it, resetting the
4355 * default size and position of the window. Used
4356 * by GUI builders only.
4359 gtk_window_reshow_with_initial_size (GtkWindow *window)
4363 g_return_if_fail (GTK_IS_WINDOW (window));
4365 widget = GTK_WIDGET (window);
4367 gtk_widget_hide (widget);
4368 gtk_widget_unrealize (widget);
4369 gtk_widget_show (widget);
4373 gtk_window_destroy (GtkObject *object)
4375 GtkWindow *window = GTK_WINDOW (object);
4377 toplevel_list = g_slist_remove (toplevel_list, window);
4379 if (window->transient_parent)
4380 gtk_window_set_transient_for (window, NULL);
4382 /* frees the icons */
4383 gtk_window_set_icon_list (window, NULL);
4385 if (window->has_user_ref_count)
4387 window->has_user_ref_count = FALSE;
4388 g_object_unref (window);
4392 gtk_window_group_remove_window (window->group, window);
4394 gtk_window_free_key_hash (window);
4396 GTK_OBJECT_CLASS (gtk_window_parent_class)->destroy (object);
4400 gtk_window_finalize (GObject *object)
4402 GtkWindow *window = GTK_WINDOW (object);
4403 GtkMnemonicHash *mnemonic_hash;
4405 g_free (window->title);
4406 g_free (window->wmclass_name);
4407 g_free (window->wmclass_class);
4408 g_free (window->wm_role);
4410 mnemonic_hash = gtk_window_get_mnemonic_hash (window, FALSE);
4412 _gtk_mnemonic_hash_free (mnemonic_hash);
4414 if (window->geometry_info)
4416 if (window->geometry_info->widget)
4417 g_signal_handlers_disconnect_by_func (window->geometry_info->widget,
4418 gtk_widget_destroyed,
4419 &window->geometry_info->widget);
4420 g_free (window->geometry_info);
4423 if (window->keys_changed_handler)
4425 g_source_remove (window->keys_changed_handler);
4426 window->keys_changed_handler = 0;
4431 g_signal_handlers_disconnect_by_func (window->screen,
4432 gtk_window_on_composited_changed, window);
4435 G_OBJECT_CLASS (gtk_window_parent_class)->finalize (object);
4439 gtk_window_show (GtkWidget *widget)
4441 GtkWindow *window = GTK_WINDOW (widget);
4442 GtkContainer *container = GTK_CONTAINER (window);
4443 gboolean need_resize;
4445 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
4447 need_resize = container->need_resize || !GTK_WIDGET_REALIZED (widget);
4448 container->need_resize = FALSE;
4452 GtkWindowGeometryInfo *info = gtk_window_get_geometry_info (window, TRUE);
4453 GtkAllocation allocation = { 0, 0 };
4454 GdkRectangle configure_request;
4455 GdkGeometry new_geometry;
4457 gboolean was_realized;
4459 /* We are going to go ahead and perform this configure request
4460 * and then emulate a configure notify by going ahead and
4461 * doing a size allocate. Sort of a synchronous
4462 * mini-copy of gtk_window_move_resize() here.
4464 gtk_window_compute_configure_request (window,
4469 /* We update this because we are going to go ahead
4470 * and gdk_window_resize() below, rather than
4473 info->last.configure_request.width = configure_request.width;
4474 info->last.configure_request.height = configure_request.height;
4476 /* and allocate the window - this is normally done
4477 * in move_resize in response to configure notify
4479 allocation.width = configure_request.width;
4480 allocation.height = configure_request.height;
4481 gtk_widget_size_allocate (widget, &allocation);
4483 /* Then we guarantee we have a realize */
4484 was_realized = FALSE;
4485 if (!GTK_WIDGET_REALIZED (widget))
4487 gtk_widget_realize (widget);
4488 was_realized = TRUE;
4491 /* Must be done after the windows are realized,
4492 * so that the decorations can be read
4494 gtk_decorated_window_calculate_frame_size (window);
4496 /* We only send configure request if we didn't just finish
4497 * creating the window; if we just created the window
4498 * then we created it with widget->allocation anyhow.
4501 gdk_window_move_resize (widget->window,
4502 configure_request.x,
4503 configure_request.y,
4504 configure_request.width,
4505 configure_request.height);
4508 gtk_container_check_resize (container);
4510 gtk_widget_map (widget);
4512 /* Try to make sure that we have some focused widget
4514 if (!window->focus_widget && !GTK_IS_PLUG (window))
4515 gtk_window_move_focus (window, GTK_DIR_TAB_FORWARD);
4518 gtk_grab_add (widget);
4522 gtk_window_hide (GtkWidget *widget)
4524 GtkWindow *window = GTK_WINDOW (widget);
4526 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
4527 gtk_widget_unmap (widget);
4530 gtk_grab_remove (widget);
4534 gtk_window_map (GtkWidget *widget)
4536 GtkWindow *window = GTK_WINDOW (widget);
4537 GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
4538 GdkWindow *toplevel;
4540 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
4542 if (window->bin.child &&
4543 GTK_WIDGET_VISIBLE (window->bin.child) &&
4544 !GTK_WIDGET_MAPPED (window->bin.child))
4545 gtk_widget_map (window->bin.child);
4548 toplevel = window->frame;
4550 toplevel = widget->window;
4552 if (window->maximize_initially)
4553 gdk_window_maximize (toplevel);
4555 gdk_window_unmaximize (toplevel);
4557 if (window->stick_initially)
4558 gdk_window_stick (toplevel);
4560 gdk_window_unstick (toplevel);
4562 if (window->iconify_initially)
4563 gdk_window_iconify (toplevel);
4565 gdk_window_deiconify (toplevel);
4567 if (priv->fullscreen_initially)
4568 gdk_window_fullscreen (toplevel);
4570 gdk_window_unfullscreen (toplevel);
4572 gdk_window_set_keep_above (toplevel, priv->above_initially);
4574 gdk_window_set_keep_below (toplevel, priv->below_initially);
4576 /* No longer use the default settings */
4577 window->need_default_size = FALSE;
4578 window->need_default_position = FALSE;
4580 if (priv->reset_type_hint)
4582 /* We should only reset the type hint when the application
4583 * used gtk_window_set_type_hint() to change the hint.
4584 * Some applications use X directly to change the properties;
4585 * in that case, we shouldn't overwrite what they did.
4587 gdk_window_set_type_hint (widget->window, priv->type_hint);
4588 priv->reset_type_hint = FALSE;
4591 gdk_window_show (widget->window);
4594 gdk_window_show (window->frame);
4596 if (!disable_startup_notification)
4598 /* Do we have a custom startup-notification id? */
4599 if (priv->startup_id != NULL)
4601 /* Make sure we have a "real" id */
4602 if (!startup_id_is_fake (priv->startup_id))
4603 gdk_notify_startup_complete_with_id (priv->startup_id);
4605 priv->startup_id = NULL;
4607 else if (!sent_startup_notification)
4609 sent_startup_notification = TRUE;
4610 gdk_notify_startup_complete ();
4616 gtk_window_map_event (GtkWidget *widget,
4619 if (!GTK_WIDGET_MAPPED (widget))
4621 /* we should be be unmapped, but are getting a MapEvent, this may happen
4622 * to toplevel XWindows if mapping was intercepted by a window manager
4623 * and an unmap request occoured while the MapRequestEvent was still
4624 * being handled. we work around this situaiton here by re-requesting
4625 * the window being unmapped. more details can be found in:
4626 * http://bugzilla.gnome.org/show_bug.cgi?id=316180
4628 gdk_window_hide (widget->window);
4634 gtk_window_unmap (GtkWidget *widget)
4636 GtkWindow *window = GTK_WINDOW (widget);
4637 GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (widget);
4638 GtkWindowGeometryInfo *info;
4639 GdkWindowState state;
4641 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
4643 gdk_window_withdraw (window->frame);
4645 gdk_window_withdraw (widget->window);
4647 window->configure_request_count = 0;
4648 window->configure_notify_received = FALSE;
4650 /* on unmap, we reset the default positioning of the window,
4651 * so it's placed again, but we don't reset the default
4652 * size of the window, so it's remembered.
4654 window->need_default_position = TRUE;
4656 info = gtk_window_get_geometry_info (window, FALSE);
4659 info->initial_pos_set = FALSE;
4660 info->position_constraints_changed = FALSE;
4663 state = gdk_window_get_state (widget->window);
4664 window->iconify_initially = (state & GDK_WINDOW_STATE_ICONIFIED) != 0;
4665 window->maximize_initially = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
4666 window->stick_initially = (state & GDK_WINDOW_STATE_STICKY) != 0;
4667 priv->above_initially = (state & GDK_WINDOW_STATE_ABOVE) != 0;
4668 priv->below_initially = (state & GDK_WINDOW_STATE_BELOW) != 0;
4672 gtk_window_realize (GtkWidget *widget)
4675 GdkWindow *parent_window;
4676 GdkWindowAttr attributes;
4677 gint attributes_mask;
4678 GtkWindowPrivate *priv;
4680 window = GTK_WINDOW (widget);
4681 priv = GTK_WINDOW_GET_PRIVATE (window);
4683 /* ensure widget tree is properly size allocated */
4684 if (widget->allocation.x == -1 &&
4685 widget->allocation.y == -1 &&
4686 widget->allocation.width == 1 &&
4687 widget->allocation.height == 1)
4689 GtkRequisition requisition;
4690 GtkAllocation allocation = { 0, 0, 200, 200 };
4692 gtk_widget_size_request (widget, &requisition);
4693 if (requisition.width || requisition.height)
4695 /* non-empty window */
4696 allocation.width = requisition.width;
4697 allocation.height = requisition.height;
4699 gtk_widget_size_allocate (widget, &allocation);
4701 _gtk_container_queue_resize (GTK_CONTAINER (widget));
4703 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
4706 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
4708 switch (window->type)
4710 case GTK_WINDOW_TOPLEVEL:
4711 attributes.window_type = GDK_WINDOW_TOPLEVEL;
4713 case GTK_WINDOW_POPUP:
4714 attributes.window_type = GDK_WINDOW_TEMP;
4717 g_warning (G_STRLOC": Unknown window type %d!", window->type);
4721 attributes.title = window->title;
4722 attributes.wmclass_name = window->wmclass_name;
4723 attributes.wmclass_class = window->wmclass_class;
4724 attributes.wclass = GDK_INPUT_OUTPUT;
4725 attributes.visual = gtk_widget_get_visual (widget);
4726 attributes.colormap = gtk_widget_get_colormap (widget);
4728 if (window->has_frame)
4730 attributes.width = widget->allocation.width + window->frame_left + window->frame_right;
4731 attributes.height = widget->allocation.height + window->frame_top + window->frame_bottom;
4732 attributes.event_mask = (GDK_EXPOSURE_MASK |
4733 GDK_KEY_PRESS_MASK |
4734 GDK_ENTER_NOTIFY_MASK |
4735 GDK_LEAVE_NOTIFY_MASK |
4736 GDK_FOCUS_CHANGE_MASK |
4737 GDK_STRUCTURE_MASK |
4738 GDK_BUTTON_MOTION_MASK |
4739 GDK_POINTER_MOTION_HINT_MASK |
4740 GDK_BUTTON_PRESS_MASK |
4741 GDK_BUTTON_RELEASE_MASK);
4743 attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
4745 window->frame = gdk_window_new (gtk_widget_get_root_window (widget),
4746 &attributes, attributes_mask);
4748 if (priv->opacity_set)
4749 gdk_window_set_opacity (window->frame, priv->opacity);
4751 gdk_window_set_user_data (window->frame, widget);
4753 attributes.window_type = GDK_WINDOW_CHILD;
4754 attributes.x = window->frame_left;
4755 attributes.y = window->frame_top;
4757 attributes_mask = GDK_WA_X | GDK_WA_Y;
4759 parent_window = window->frame;
4761 g_signal_connect (window,
4763 G_CALLBACK (gtk_window_event),
4768 attributes_mask = 0;
4769 parent_window = gtk_widget_get_root_window (widget);
4772 attributes.width = widget->allocation.width;
4773 attributes.height = widget->allocation.height;
4774 attributes.event_mask = gtk_widget_get_events (widget);
4775 attributes.event_mask |= (GDK_EXPOSURE_MASK |
4776 GDK_KEY_PRESS_MASK |
4777 GDK_KEY_RELEASE_MASK |
4778 GDK_ENTER_NOTIFY_MASK |
4779 GDK_LEAVE_NOTIFY_MASK |
4780 GDK_FOCUS_CHANGE_MASK |
4781 GDK_STRUCTURE_MASK);
4782 attributes.type_hint = priv->type_hint;
4784 attributes_mask |= GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_TYPE_HINT;
4785 attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
4786 attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
4788 widget->window = gdk_window_new (parent_window, &attributes, attributes_mask);
4790 if (!window->has_frame && priv->opacity_set)
4791 gdk_window_set_opacity (widget->window, priv->opacity);
4793 gdk_window_enable_synchronized_configure (widget->window);
4795 gdk_window_set_user_data (widget->window, window);
4797 widget->style = gtk_style_attach (widget->style, widget->window);
4798 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
4800 gtk_style_set_background (widget->style, window->frame, GTK_STATE_NORMAL);
4802 /* This is a bad hack to set the window background. */
4803 gtk_window_paint (widget, NULL);
4805 if (window->transient_parent &&
4806 GTK_WIDGET_REALIZED (window->transient_parent))
4807 gdk_window_set_transient_for (widget->window,
4808 GTK_WIDGET (window->transient_parent)->window);
4810 if (window->wm_role)
4811 gdk_window_set_role (widget->window, window->wm_role);
4813 if (!window->decorated)
4814 gdk_window_set_decorations (widget->window, 0);
4816 if (!priv->deletable)
4817 gdk_window_set_functions (widget->window, GDK_FUNC_ALL | GDK_FUNC_CLOSE);
4819 if (gtk_window_get_skip_pager_hint (window))
4820 gdk_window_set_skip_pager_hint (widget->window, TRUE);
4822 if (gtk_window_get_skip_taskbar_hint (window))
4823 gdk_window_set_skip_taskbar_hint (widget->window, TRUE);
4825 if (gtk_window_get_accept_focus (window))
4826 gdk_window_set_accept_focus (widget->window, TRUE);
4828 gdk_window_set_accept_focus (widget->window, FALSE);
4830 if (gtk_window_get_focus_on_map (window))
4831 gdk_window_set_focus_on_map (widget->window, TRUE);
4833 gdk_window_set_focus_on_map (widget->window, FALSE);
4836 gdk_window_set_modal_hint (widget->window, TRUE);
4838 gdk_window_set_modal_hint (widget->window, FALSE);
4840 if (priv->startup_id)
4842 #ifdef GDK_WINDOWING_X11
4843 guint32 timestamp = extract_time_from_startup_id (priv->startup_id);
4844 if (timestamp != GDK_CURRENT_TIME)
4845 gdk_x11_window_set_user_time (widget->window, timestamp);
4847 if (!startup_id_is_fake (priv->startup_id))
4848 gdk_window_set_startup_id (widget->window, priv->startup_id);
4852 gtk_window_realize_icon (window);
4856 gtk_window_unrealize (GtkWidget *widget)
4859 GtkWindowGeometryInfo *info;
4861 window = GTK_WINDOW (widget);
4863 /* On unrealize, we reset the size of the window such
4864 * that we will re-apply the default sizing stuff
4865 * next time we show the window.
4867 * Default positioning is reset on unmap, instead of unrealize.
4869 window->need_default_size = TRUE;
4870 info = gtk_window_get_geometry_info (window, FALSE);
4873 info->resize_width = -1;
4874 info->resize_height = -1;
4875 info->last.configure_request.x = 0;
4876 info->last.configure_request.y = 0;
4877 info->last.configure_request.width = -1;
4878 info->last.configure_request.height = -1;
4879 /* be sure we reset geom hints on re-realize */
4880 info->last.flags = 0;
4885 gdk_window_set_user_data (window->frame, NULL);
4886 gdk_window_destroy (window->frame);
4887 window->frame = NULL;
4891 gtk_window_unrealize_icon (window);
4893 GTK_WIDGET_CLASS (gtk_window_parent_class)->unrealize (widget);
4897 gtk_window_size_request (GtkWidget *widget,
4898 GtkRequisition *requisition)
4903 window = GTK_WINDOW (widget);
4904 bin = GTK_BIN (window);
4906 requisition->width = GTK_CONTAINER (window)->border_width * 2;
4907 requisition->height = GTK_CONTAINER (window)->border_width * 2;
4909 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
4911 GtkRequisition child_requisition;
4913 gtk_widget_size_request (bin->child, &child_requisition);
4915 requisition->width += child_requisition.width;
4916 requisition->height += child_requisition.height;
4921 gtk_window_size_allocate (GtkWidget *widget,
4922 GtkAllocation *allocation)
4925 GtkAllocation child_allocation;
4927 window = GTK_WINDOW (widget);
4928 widget->allocation = *allocation;
4930 if (window->bin.child && GTK_WIDGET_VISIBLE (window->bin.child))
4932 child_allocation.x = GTK_CONTAINER (window)->border_width;
4933 child_allocation.y = GTK_CONTAINER (window)->border_width;
4934 child_allocation.width =
4935 MAX (1, (gint)allocation->width - child_allocation.x * 2);
4936 child_allocation.height =
4937 MAX (1, (gint)allocation->height - child_allocation.y * 2);
4939 gtk_widget_size_allocate (window->bin.child, &child_allocation);
4942 if (GTK_WIDGET_REALIZED (widget) && window->frame)
4944 gdk_window_resize (window->frame,
4945 allocation->width + window->frame_left + window->frame_right,
4946 allocation->height + window->frame_top + window->frame_bottom);
4951 gtk_window_event (GtkWidget *widget, GdkEvent *event)
4954 gboolean return_val;
4956 window = GTK_WINDOW (widget);
4958 if (window->frame && (event->any.window == window->frame))
4960 if ((event->type != GDK_KEY_PRESS) &&
4961 (event->type != GDK_KEY_RELEASE) &&
4962 (event->type != GDK_FOCUS_CHANGE))
4964 g_signal_stop_emission_by_name (widget, "event");
4966 g_signal_emit (widget, window_signals[FRAME_EVENT], 0, event, &return_val);
4971 g_object_unref (event->any.window);
4972 event->any.window = g_object_ref (widget->window);
4980 gtk_window_frame_event (GtkWindow *window, GdkEvent *event)
4982 GdkEventConfigure *configure_event;
4985 switch (event->type)
4988 configure_event = (GdkEventConfigure *)event;
4990 /* Invalidate the decorations */
4993 rect.width = configure_event->width;
4994 rect.height = configure_event->height;
4996 gdk_window_invalidate_rect (window->frame, &rect, FALSE);
4998 /* Pass on the (modified) configure event */
4999 configure_event->width -= window->frame_left + window->frame_right;
5000 configure_event->height -= window->frame_top + window->frame_bottom;
5001 return gtk_window_configure_event (GTK_WIDGET (window), configure_event);
5010 gtk_window_configure_event (GtkWidget *widget,
5011 GdkEventConfigure *event)
5013 GtkWindow *window = GTK_WINDOW (widget);
5014 gboolean expected_reply = window->configure_request_count > 0;
5016 /* window->configure_request_count incremented for each
5017 * configure request, and decremented to a min of 0 for
5018 * each configure notify.
5020 * All it means is that we know we will get at least
5021 * window->configure_request_count more configure notifies.
5022 * We could get more configure notifies than that; some
5023 * of the configure notifies we get may be unrelated to
5024 * the configure requests. But we will get at least
5025 * window->configure_request_count notifies.
5028 if (window->configure_request_count > 0)
5030 window->configure_request_count -= 1;
5031 gdk_window_thaw_toplevel_updates_libgtk_only (widget->window);
5034 /* As an optimization, we avoid a resize when possible.
5036 * The only times we can avoid a resize are:
5037 * - we know only the position changed, not the size
5038 * - we know we have made more requests and so will get more
5039 * notifies and can wait to resize when we get them
5042 if (!expected_reply &&
5043 (widget->allocation.width == event->width &&
5044 widget->allocation.height == event->height))
5046 gdk_window_configure_finished (widget->window);
5051 * If we do need to resize, we do that by:
5052 * - filling in widget->allocation with the new size
5053 * - setting configure_notify_received to TRUE
5054 * for use in gtk_window_move_resize()
5055 * - queueing a resize, leading to invocation of
5056 * gtk_window_move_resize() in an idle handler
5060 window->configure_notify_received = TRUE;
5062 widget->allocation.width = event->width;
5063 widget->allocation.height = event->height;
5065 _gtk_container_queue_resize (GTK_CONTAINER (widget));
5070 /* the accel_key and accel_mods fields of the key have to be setup
5071 * upon calling this function. it'll then return whether that key
5072 * is at all used as accelerator, and if so will OR in the
5073 * accel_flags member of the key.
5076 _gtk_window_query_nonaccels (GtkWindow *window,
5078 GdkModifierType accel_mods)
5080 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
5082 /* movement keys are considered locked accels */
5085 static const guint bindings[] = {
5086 GDK_space, GDK_KP_Space, GDK_Return, GDK_ISO_Enter, GDK_KP_Enter, GDK_Up, GDK_KP_Up, GDK_Down, GDK_KP_Down,
5087 GDK_Left, GDK_KP_Left, GDK_Right, GDK_KP_Right, GDK_Tab, GDK_KP_Tab, GDK_ISO_Left_Tab,
5091 for (i = 0; i < G_N_ELEMENTS (bindings); i++)
5092 if (bindings[i] == accel_key)
5096 /* mnemonics are considered locked accels */
5097 if (accel_mods == window->mnemonic_modifier)
5099 GtkMnemonicHash *mnemonic_hash = gtk_window_get_mnemonic_hash (window, FALSE);
5100 if (mnemonic_hash && _gtk_mnemonic_hash_lookup (mnemonic_hash, accel_key))
5108 * gtk_window_propagate_key_event:
5109 * @window: a #GtkWindow
5110 * @event: a #GdkEventKey
5112 * Propagate a key press or release event to the focus widget and
5113 * up the focus container chain until a widget handles @event.
5114 * This is normally called by the default ::key_press_event and
5115 * ::key_release_event handlers for toplevel windows,
5116 * however in some cases it may be useful to call this directly when
5117 * overriding the standard key handling for a toplevel window.
5119 * Return value: %TRUE if a widget in the focus chain handled the event.
5122 gtk_window_propagate_key_event (GtkWindow *window,
5125 gboolean handled = FALSE;
5126 GtkWidget *widget, *focus;
5128 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
5130 widget = GTK_WIDGET (window);
5131 focus = window->focus_widget;
5133 g_object_ref (focus);
5136 focus && focus != widget &&
5137 gtk_widget_get_toplevel (focus) == widget)
5141 if (GTK_WIDGET_IS_SENSITIVE (focus))
5142 handled = gtk_widget_event (focus, (GdkEvent*) event);
5144 parent = focus->parent;
5146 g_object_ref (parent);
5148 g_object_unref (focus);
5154 g_object_unref (focus);
5160 gtk_window_key_press_event (GtkWidget *widget,
5163 GtkWindow *window = GTK_WINDOW (widget);
5164 gboolean handled = FALSE;
5166 /* handle mnemonics and accelerators */
5168 handled = gtk_window_activate_key (window, event);
5170 /* handle focus widget key events */
5172 handled = gtk_window_propagate_key_event (window, event);
5174 /* Chain up, invokes binding set */
5176 handled = GTK_WIDGET_CLASS (gtk_window_parent_class)->key_press_event (widget, event);
5182 gtk_window_key_release_event (GtkWidget *widget,
5185 GtkWindow *window = GTK_WINDOW (widget);
5186 gboolean handled = FALSE;
5188 /* handle focus widget key events */
5190 handled = gtk_window_propagate_key_event (window, event);
5192 /* Chain up, invokes binding set */
5194 handled = GTK_WIDGET_CLASS (gtk_window_parent_class)->key_release_event (widget, event);
5200 gtk_window_real_activate_default (GtkWindow *window)
5202 gtk_window_activate_default (window);
5206 gtk_window_real_activate_focus (GtkWindow *window)
5208 gtk_window_activate_focus (window);
5212 gtk_window_move_focus (GtkWindow *window,
5213 GtkDirectionType dir)
5215 gtk_widget_child_focus (GTK_WIDGET (window), dir);
5217 if (!GTK_CONTAINER (window)->focus_child)
5218 gtk_window_set_focus (window, NULL);
5222 gtk_window_enter_notify_event (GtkWidget *widget,
5223 GdkEventCrossing *event)
5229 gtk_window_leave_notify_event (GtkWidget *widget,
5230 GdkEventCrossing *event)
5236 do_focus_change (GtkWidget *widget,
5239 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
5241 g_object_ref (widget);
5244 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
5246 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
5248 fevent->focus_change.type = GDK_FOCUS_CHANGE;
5249 fevent->focus_change.window = widget->window;
5251 g_object_ref (widget->window);
5252 fevent->focus_change.in = in;
5254 gtk_widget_event (widget, fevent);
5256 g_object_notify (G_OBJECT (widget), "has-focus");
5258 g_object_unref (widget);
5259 gdk_event_free (fevent);
5263 gtk_window_focus_in_event (GtkWidget *widget,
5264 GdkEventFocus *event)
5266 GtkWindow *window = GTK_WINDOW (widget);
5268 /* It appears spurious focus in events can occur when
5269 * the window is hidden. So we'll just check to see if
5270 * the window is visible before actually handling the
5273 if (GTK_WIDGET_VISIBLE (widget))
5275 _gtk_window_set_has_toplevel_focus (window, TRUE);
5276 _gtk_window_set_is_active (window, TRUE);
5283 gtk_window_focus_out_event (GtkWidget *widget,
5284 GdkEventFocus *event)
5286 GtkWindow *window = GTK_WINDOW (widget);
5288 _gtk_window_set_has_toplevel_focus (window, FALSE);
5289 _gtk_window_set_is_active (window, FALSE);
5294 static GdkAtom atom_rcfiles = GDK_NONE;
5295 static GdkAtom atom_iconthemes = GDK_NONE;
5298 send_client_message_to_embedded_windows (GtkWidget *widget,
5299 GdkAtom message_type)
5301 GList *embedded_windows;
5303 embedded_windows = g_object_get_qdata (G_OBJECT (widget), quark_gtk_embedded);
5304 if (embedded_windows)
5306 GdkEvent *send_event = gdk_event_new (GDK_CLIENT_EVENT);
5309 for (i = 0; i < 5; i++)
5310 send_event->client.data.l[i] = 0;
5311 send_event->client.data_format = 32;
5312 send_event->client.message_type = message_type;
5314 while (embedded_windows)
5316 GdkNativeWindow xid = (GdkNativeWindow) embedded_windows->data;
5317 gdk_event_send_client_message_for_display (gtk_widget_get_display (widget), send_event, xid);
5318 embedded_windows = embedded_windows->next;
5321 gdk_event_free (send_event);
5326 gtk_window_client_event (GtkWidget *widget,
5327 GdkEventClient *event)
5331 atom_rcfiles = gdk_atom_intern_static_string ("_GTK_READ_RCFILES");
5332 atom_iconthemes = gdk_atom_intern_static_string ("_GTK_LOAD_ICONTHEMES");
5335 if (event->message_type == atom_rcfiles)
5337 send_client_message_to_embedded_windows (widget, atom_rcfiles);
5338 gtk_rc_reparse_all_for_settings (gtk_widget_get_settings (widget), FALSE);
5341 if (event->message_type == atom_iconthemes)
5343 send_client_message_to_embedded_windows (widget, atom_iconthemes);
5344 _gtk_icon_theme_check_reload (gtk_widget_get_display (widget));
5351 gtk_window_check_resize (GtkContainer *container)
5353 GtkWindow *window = GTK_WINDOW (container);
5355 if (GTK_WIDGET_VISIBLE (container))
5356 gtk_window_move_resize (window);
5360 gtk_window_focus (GtkWidget *widget,
5361 GtkDirectionType direction)
5365 GtkContainer *container;
5366 GtkWidget *old_focus_child;
5369 container = GTK_CONTAINER (widget);
5370 window = GTK_WINDOW (widget);
5371 bin = GTK_BIN (widget);
5373 old_focus_child = container->focus_child;
5375 /* We need a special implementation here to deal properly with wrapping
5376 * around in the tab chain without the danger of going into an
5379 if (old_focus_child)
5381 if (gtk_widget_child_focus (old_focus_child, direction))
5385 if (window->focus_widget)
5387 if (direction == GTK_DIR_LEFT ||
5388 direction == GTK_DIR_RIGHT ||
5389 direction == GTK_DIR_UP ||
5390 direction == GTK_DIR_DOWN)
5395 /* Wrapped off the end, clear the focus setting for the toplpevel */
5396 parent = window->focus_widget->parent;
5399 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
5400 parent = GTK_WIDGET (parent)->parent;
5403 gtk_window_set_focus (GTK_WINDOW (container), NULL);
5406 /* Now try to focus the first widget in the window */
5409 if (gtk_widget_child_focus (bin->child, direction))
5417 gtk_window_real_set_focus (GtkWindow *window,
5420 GtkWidget *old_focus = window->focus_widget;
5421 gboolean had_default = FALSE;
5422 gboolean focus_had_default = FALSE;
5423 gboolean old_focus_had_default = FALSE;
5427 g_object_ref (old_focus);
5428 g_object_freeze_notify (G_OBJECT (old_focus));
5429 old_focus_had_default = GTK_WIDGET_HAS_DEFAULT (old_focus);
5433 g_object_ref (focus);
5434 g_object_freeze_notify (G_OBJECT (focus));
5435 focus_had_default = GTK_WIDGET_HAS_DEFAULT (focus);
5438 if (window->default_widget)
5439 had_default = GTK_WIDGET_HAS_DEFAULT (window->default_widget);
5441 if (window->focus_widget)
5443 if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) &&
5444 (window->focus_widget != window->default_widget))
5446 GTK_WIDGET_UNSET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT);
5447 gtk_widget_queue_draw (window->focus_widget);
5449 if (window->default_widget)
5450 GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
5453 window->focus_widget = NULL;
5455 if (window->has_focus)
5456 do_focus_change (old_focus, FALSE);
5458 g_object_notify (G_OBJECT (old_focus), "is-focus");
5461 /* The above notifications may have set a new focus widget,
5462 * if so, we don't want to override it.
5464 if (focus && !window->focus_widget)
5466 window->focus_widget = focus;
5468 if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) &&
5469 (window->focus_widget != window->default_widget))
5471 if (GTK_WIDGET_CAN_DEFAULT (window->focus_widget))
5472 GTK_WIDGET_SET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT);
5474 if (window->default_widget)
5475 GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
5478 if (window->has_focus)
5479 do_focus_change (window->focus_widget, TRUE);
5481 g_object_notify (G_OBJECT (window->focus_widget), "is-focus");
5484 /* If the default widget changed, a redraw will have been queued
5485 * on the old and new default widgets by gtk_window_set_default(), so
5486 * we only have to worry about the case where it didn't change.
5487 * We'll sometimes queue a draw twice on the new widget but that
5490 if (window->default_widget &&
5491 (had_default != GTK_WIDGET_HAS_DEFAULT (window->default_widget)))
5492 gtk_widget_queue_draw (window->default_widget);
5496 if (old_focus_had_default != GTK_WIDGET_HAS_DEFAULT (old_focus))
5497 gtk_widget_queue_draw (old_focus);
5499 g_object_thaw_notify (G_OBJECT (old_focus));
5500 g_object_unref (old_focus);
5504 if (focus_had_default != GTK_WIDGET_HAS_DEFAULT (focus))
5505 gtk_widget_queue_draw (focus);
5507 g_object_thaw_notify (G_OBJECT (focus));
5508 g_object_unref (focus);
5513 * _gtk_window_unset_focus_and_default:
5514 * @window: a #GtkWindow
5515 * @widget: a widget inside of @window
5517 * Checks whether the focus and default widgets of @window are
5518 * @widget or a descendent of @widget, and if so, unset them.
5521 _gtk_window_unset_focus_and_default (GtkWindow *window,
5527 g_object_ref (window);
5528 g_object_ref (widget);
5530 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
5532 child = window->focus_widget;
5534 while (child && child != widget)
5535 child = child->parent;
5537 if (child == widget)
5538 gtk_window_set_focus (GTK_WINDOW (window), NULL);
5541 child = window->default_widget;
5543 while (child && child != widget)
5544 child = child->parent;
5546 if (child == widget)
5547 gtk_window_set_default (window, NULL);
5549 g_object_unref (widget);
5550 g_object_unref (window);
5553 /*********************************
5554 * Functions related to resizing *
5555 *********************************/
5557 /* This function doesn't constrain to geometry hints */
5559 gtk_window_compute_configure_request_size (GtkWindow *window,
5563 GtkRequisition requisition;
5564 GtkWindowGeometryInfo *info;
5568 * - we've done a size request
5571 widget = GTK_WIDGET (window);
5573 info = gtk_window_get_geometry_info (window, FALSE);
5575 if (window->need_default_size)
5577 gtk_widget_get_child_requisition (widget, &requisition);
5579 /* Default to requisition */
5580 *width = requisition.width;
5581 *height = requisition.height;
5583 /* If window is empty so requests 0, default to random nonzero size */
5584 if (*width == 0 && *height == 0)
5590 /* Override requisition with default size */
5594 gint base_width = 0;
5595 gint base_height = 0;
5597 gint min_height = 0;
5599 gint height_inc = 1;
5601 if (info->default_is_geometry &&
5602 (info->default_width > 0 || info->default_height > 0))
5604 GdkGeometry geometry;
5607 gtk_window_compute_hints (window, &geometry, &flags);
5609 if (flags & GDK_HINT_BASE_SIZE)
5611 base_width = geometry.base_width;
5612 base_height = geometry.base_height;
5614 if (flags & GDK_HINT_MIN_SIZE)
5616 min_width = geometry.min_width;
5617 min_height = geometry.min_height;
5619 if (flags & GDK_HINT_RESIZE_INC)
5621 width_inc = geometry.width_inc;
5622 height_inc = geometry.height_inc;
5626 if (info->default_width > 0)
5627 *width = MAX (info->default_width * width_inc + base_width, min_width);
5629 if (info->default_height > 0)
5630 *height = MAX (info->default_height * height_inc + base_height, min_height);
5635 /* Default to keeping current size */
5636 *width = widget->allocation.width;
5637 *height = widget->allocation.height;
5640 /* Override any size with gtk_window_resize() values */
5643 if (info->resize_width > 0)
5644 *width = info->resize_width;
5646 if (info->resize_height > 0)
5647 *height = info->resize_height;
5651 static GtkWindowPosition
5652 get_effective_position (GtkWindow *window)
5654 GtkWindowPosition pos = window->position;
5655 if (pos == GTK_WIN_POS_CENTER_ON_PARENT &&
5656 (window->transient_parent == NULL ||
5657 !GTK_WIDGET_MAPPED (window->transient_parent)))
5658 pos = GTK_WIN_POS_NONE;
5664 get_center_monitor_of_window (GtkWindow *window)
5666 /* We could try to sort out the relative positions of the monitors and
5667 * stuff, or we could just be losers and assume you have a row
5668 * or column of monitors.
5670 return gdk_screen_get_n_monitors (gtk_window_check_screen (window)) / 2;
5674 get_monitor_containing_pointer (GtkWindow *window)
5678 GdkScreen *window_screen;
5679 GdkScreen *pointer_screen;
5681 window_screen = gtk_window_check_screen (window);
5682 gdk_display_get_pointer (gdk_screen_get_display (window_screen),
5686 if (pointer_screen == window_screen)
5687 monitor_num = gdk_screen_get_monitor_at_point (pointer_screen, px, py);
5695 center_window_on_monitor (GtkWindow *window,
5701 GdkRectangle monitor;
5704 monitor_num = get_monitor_containing_pointer (window);
5706 if (monitor_num == -1)
5707 monitor_num = get_center_monitor_of_window (window);
5709 gdk_screen_get_monitor_geometry (gtk_window_check_screen (window),
5710 monitor_num, &monitor);
5712 *x = (monitor.width - w) / 2 + monitor.x;
5713 *y = (monitor.height - h) / 2 + monitor.y;
5715 /* Be sure we aren't off the monitor, ignoring _NET_WM_STRUT
5716 * and WM decorations.
5730 if (extent > clamp_extent)
5732 *base = clamp_base + clamp_extent/2 - extent/2;
5733 else if (*base < clamp_base)
5735 else if (*base + extent > clamp_base + clamp_extent)
5736 *base = clamp_base + clamp_extent - extent;
5740 clamp_window_to_rectangle (gint *x,
5744 const GdkRectangle *rect)
5746 #ifdef DEBUGGING_OUTPUT
5747 g_print ("%s: %+d%+d %dx%d: %+d%+d: %dx%d", __FUNCTION__, rect->x, rect->y, rect->width, rect->height, *x, *y, w, h);
5750 /* If it is too large, center it. If it fits on the monitor but is
5751 * partially outside, move it to the closest edge. Do this
5752 * separately in x and y directions.
5754 clamp (x, w, rect->x, rect->width);
5755 clamp (y, h, rect->y, rect->height);
5756 #ifdef DEBUGGING_OUTPUT
5757 g_print (" ==> %+d%+d: %dx%d\n", *x, *y, w, h);
5763 gtk_window_compute_configure_request (GtkWindow *window,
5764 GdkRectangle *request,
5765 GdkGeometry *geometry,
5768 GdkGeometry new_geometry;
5772 GtkWindowPosition pos;
5773 GtkWidget *parent_widget;
5774 GtkWindowGeometryInfo *info;
5778 widget = GTK_WIDGET (window);
5780 screen = gtk_window_check_screen (window);
5782 gtk_widget_size_request (widget, NULL);
5783 gtk_window_compute_configure_request_size (window, (guint *)&w, (guint *)&h);
5785 gtk_window_compute_hints (window, &new_geometry, &new_flags);
5786 gtk_window_constrain_size (window,
5787 &new_geometry, new_flags,
5791 parent_widget = (GtkWidget*) window->transient_parent;
5793 pos = get_effective_position (window);
5794 info = gtk_window_get_geometry_info (window, FALSE);
5796 /* by default, don't change position requested */
5799 x = info->last.configure_request.x;
5800 y = info->last.configure_request.y;
5809 if (window->need_default_position)
5812 /* FIXME this all interrelates with window gravity.
5813 * For most of them I think we want to set GRAVITY_CENTER.
5815 * Not sure how to go about that.
5820 /* here we are only handling CENTER_ALWAYS
5821 * as it relates to default positioning,
5822 * where it's equivalent to simply CENTER
5824 case GTK_WIN_POS_CENTER_ALWAYS:
5825 case GTK_WIN_POS_CENTER:
5826 center_window_on_monitor (window, w, h, &x, &y);
5829 case GTK_WIN_POS_CENTER_ON_PARENT:
5832 GdkRectangle monitor;
5835 g_assert (GTK_WIDGET_MAPPED (parent_widget)); /* established earlier */
5837 if (parent_widget->window != NULL)
5838 monitor_num = gdk_screen_get_monitor_at_window (screen,
5839 parent_widget->window);
5843 gdk_window_get_origin (parent_widget->window,
5846 x = ox + (parent_widget->allocation.width - w) / 2;
5847 y = oy + (parent_widget->allocation.height - h) / 2;
5849 /* Clamp onto current monitor, ignoring _NET_WM_STRUT and
5850 * WM decorations. If parent wasn't on a monitor, just
5853 if (monitor_num >= 0)
5855 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
5856 clamp_window_to_rectangle (&x, &y, w, h, &monitor);
5861 case GTK_WIN_POS_MOUSE:
5863 gint screen_width = gdk_screen_get_width (screen);
5864 gint screen_height = gdk_screen_get_height (screen);
5866 GdkRectangle monitor;
5867 GdkScreen *pointer_screen;
5870 gdk_display_get_pointer (gdk_screen_get_display (screen),
5874 if (pointer_screen == screen)
5875 monitor_num = gdk_screen_get_monitor_at_point (screen, px, py);
5881 x = CLAMP (x, 0, screen_width - w);
5882 y = CLAMP (y, 0, screen_height - h);
5884 /* Clamp onto current monitor, ignoring _NET_WM_STRUT and
5885 * WM decorations. Don't try to figure out what's going
5886 * on if the mouse wasn't inside a monitor.
5888 if (monitor_num >= 0)
5890 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
5891 clamp_window_to_rectangle (&x, &y, w, h, &monitor);
5899 } /* if (window->need_default_position) */
5901 if (window->need_default_position && info &&
5902 info->initial_pos_set)
5904 x = info->initial_x;
5905 y = info->initial_y;
5906 gtk_window_constrain_position (window, w, h, &x, &y);
5912 request->height = h;
5915 *geometry = new_geometry;
5921 gtk_window_constrain_position (GtkWindow *window,
5927 /* See long comments in gtk_window_move_resize()
5928 * on when it's safe to call this function.
5930 if (window->position == GTK_WIN_POS_CENTER_ALWAYS)
5932 gint center_x, center_y;
5934 center_window_on_monitor (window, new_width, new_height, ¢er_x, ¢er_y);
5942 gtk_window_move_resize (GtkWindow *window)
5946 * First we determine whether any information has changed that would
5947 * cause us to revise our last configure request. If we would send
5948 * a different configure request from last time, then
5949 * configure_request_size_changed = TRUE or
5950 * configure_request_pos_changed = TRUE. configure_request_size_changed
5951 * may be true due to new hints, a gtk_window_resize(), or whatever.
5952 * configure_request_pos_changed may be true due to gtk_window_set_position()
5953 * or gtk_window_move().
5955 * If the configure request has changed, we send off a new one. To
5956 * ensure GTK+ invariants are maintained (resize queue does what it
5957 * should), we go ahead and size_allocate the requested size in this
5960 * If the configure request has not changed, we don't ever resend
5961 * it, because it could mean fighting the user or window manager.
5964 * To prepare the configure request, we come up with a base size/pos:
5965 * - the one from gtk_window_move()/gtk_window_resize()
5966 * - else default_width, default_height if we haven't ever
5968 * - else the size request if we haven't ever been mapped,
5969 * as a substitute default size
5970 * - else the current size of the window, as received from
5971 * configure notifies (i.e. the current allocation)
5973 * If GTK_WIN_POS_CENTER_ALWAYS is active, we constrain
5974 * the position request to be centered.
5977 GtkContainer *container;
5978 GtkWindowGeometryInfo *info;
5979 GdkGeometry new_geometry;
5981 GdkRectangle new_request;
5982 gboolean configure_request_size_changed;
5983 gboolean configure_request_pos_changed;
5984 gboolean hints_changed; /* do we need to send these again */
5985 GtkWindowLastGeometryInfo saved_last_info;
5987 widget = GTK_WIDGET (window);
5988 container = GTK_CONTAINER (widget);
5989 info = gtk_window_get_geometry_info (window, TRUE);
5991 configure_request_size_changed = FALSE;
5992 configure_request_pos_changed = FALSE;
5994 gtk_window_compute_configure_request (window, &new_request,
5995 &new_geometry, &new_flags);
5997 /* This check implies the invariant that we never set info->last
5998 * without setting the hints and sending off a configure request.
6000 * If we change info->last without sending the request, we may
6003 if (info->last.configure_request.x != new_request.x ||
6004 info->last.configure_request.y != new_request.y)
6005 configure_request_pos_changed = TRUE;
6007 if ((info->last.configure_request.width != new_request.width ||
6008 info->last.configure_request.height != new_request.height))
6009 configure_request_size_changed = TRUE;
6011 hints_changed = FALSE;
6013 if (!gtk_window_compare_hints (&info->last.geometry, info->last.flags,
6014 &new_geometry, new_flags))
6016 hints_changed = TRUE;
6019 /* Position Constraints
6020 * ====================
6022 * POS_CENTER_ALWAYS is conceptually a constraint rather than
6023 * a default. The other POS_ values are used only when the
6024 * window is shown, not after that.
6026 * However, we can't implement a position constraint as
6027 * "anytime the window size changes, center the window"
6028 * because this may well end up fighting the WM or user. In
6029 * fact it gets in an infinite loop with at least one WM.
6031 * Basically, applications are in no way in a position to
6032 * constrain the position of a window, with one exception:
6033 * override redirect windows. (Really the intended purpose
6034 * of CENTER_ALWAYS anyhow, I would think.)
6036 * So the way we implement this "constraint" is to say that when WE
6037 * cause a move or resize, i.e. we make a configure request changing
6038 * window size, we recompute the CENTER_ALWAYS position to reflect
6039 * the new window size, and include it in our request. Also, if we
6040 * just turned on CENTER_ALWAYS we snap to center with a new
6041 * request. Otherwise, if we are just NOTIFIED of a move or resize
6042 * done by someone else e.g. the window manager, we do NOT send a
6043 * new configure request.
6045 * For override redirect windows, this works fine; all window
6046 * sizes are from our configure requests. For managed windows,
6047 * it is at least semi-sane, though who knows what the
6048 * app author is thinking.
6051 /* This condition should be kept in sync with the condition later on
6052 * that determines whether we send a configure request. i.e. we
6053 * should do this position constraining anytime we were going to
6054 * send a configure request anyhow, plus when constraints have
6057 if (configure_request_pos_changed ||
6058 configure_request_size_changed ||
6060 info->position_constraints_changed)
6062 /* We request the constrained position if:
6063 * - we were changing position, and need to clamp
6064 * the change to the constraint
6065 * - we're changing the size anyway
6066 * - set_position() was called to toggle CENTER_ALWAYS on
6069 gtk_window_constrain_position (window,
6075 /* Update whether we need to request a move */
6076 if (info->last.configure_request.x != new_request.x ||
6077 info->last.configure_request.y != new_request.y)
6078 configure_request_pos_changed = TRUE;
6080 configure_request_pos_changed = FALSE;
6084 if (window->type == GTK_WINDOW_TOPLEVEL)
6086 int notify_x, notify_y;
6088 /* this is the position from the last configure notify */
6089 gdk_window_get_position (widget->window, ¬ify_x, ¬ify_y);
6091 g_message ("--- %s ---\n"
6092 "last : %d,%d\t%d x %d\n"
6093 "this : %d,%d\t%d x %d\n"
6094 "alloc : %d,%d\t%d x %d\n"
6096 "resize: \t%d x %d\n"
6097 "size_changed: %d pos_changed: %d hints_changed: %d\n"
6098 "configure_notify_received: %d\n"
6099 "configure_request_count: %d\n"
6100 "position_constraints_changed: %d\n",
6101 window->title ? window->title : "(no title)",
6102 info->last.configure_request.x,
6103 info->last.configure_request.y,
6104 info->last.configure_request.width,
6105 info->last.configure_request.height,
6111 widget->allocation.width,
6112 widget->allocation.height,
6113 widget->requisition.width,
6114 widget->requisition.height,
6116 info->resize_height,
6117 configure_request_pos_changed,
6118 configure_request_size_changed,
6120 window->configure_notify_received,
6121 window->configure_request_count,
6122 info->position_constraints_changed);
6126 saved_last_info = info->last;
6127 info->last.geometry = new_geometry;
6128 info->last.flags = new_flags;
6129 info->last.configure_request = new_request;
6131 /* need to set PPosition so the WM will look at our position,
6132 * but we don't want to count PPosition coming and going as a hints
6133 * change for future iterations. So we saved info->last prior to
6137 /* Also, if the initial position was explicitly set, then we always
6138 * toggle on PPosition. This makes gtk_window_move(window, 0, 0)
6142 /* Also, we toggle on PPosition if GTK_WIN_POS_ is in use and
6143 * this is an initial map
6146 if ((configure_request_pos_changed ||
6147 info->initial_pos_set ||
6148 (window->need_default_position &&
6149 get_effective_position (window) != GTK_WIN_POS_NONE)) &&
6150 (new_flags & GDK_HINT_POS) == 0)
6152 new_flags |= GDK_HINT_POS;
6153 hints_changed = TRUE;
6156 /* Set hints if necessary
6159 gdk_window_set_geometry_hints (widget->window,
6163 /* handle resizing/moving and widget tree allocation
6165 if (window->configure_notify_received)
6167 GtkAllocation allocation;
6169 /* If we have received a configure event since
6170 * the last time in this function, we need to
6171 * accept our new size and size_allocate child widgets.
6172 * (see gtk_window_configure_event() for more details).
6174 * 1 or more configure notifies may have been received.
6175 * Also, configure_notify_received will only be TRUE
6176 * if all expected configure notifies have been received
6177 * (one per configure request), as an optimization.
6180 window->configure_notify_received = FALSE;
6182 /* gtk_window_configure_event() filled in widget->allocation */
6183 allocation = widget->allocation;
6184 gtk_widget_size_allocate (widget, &allocation);
6186 gdk_window_process_updates (widget->window, TRUE);
6188 gdk_window_configure_finished (widget->window);
6190 /* If the configure request changed, it means that
6192 * 1) coincidentally changed hints or widget properties
6193 * impacting the configure request before getting
6194 * a configure notify, or
6195 * 2) some broken widget is changing its size request
6196 * during size allocation, resulting in
6197 * a false appearance of changed configure request.
6199 * For 1), we could just go ahead and ask for the
6200 * new size right now, but doing that for 2)
6201 * might well be fighting the user (and can even
6202 * trigger a loop). Since we really don't want to
6203 * do that, we requeue a resize in hopes that
6204 * by the time it gets handled, the child has seen
6205 * the light and is willing to go along with the
6206 * new size. (this happens for the zvt widget, since
6207 * the size_allocate() above will have stored the
6208 * requisition corresponding to the new size in the
6211 * This doesn't buy us anything for 1), but it shouldn't
6212 * hurt us too badly, since it is what would have
6213 * happened if we had gotten the configure event before
6214 * the new size had been set.
6217 if (configure_request_size_changed ||
6218 configure_request_pos_changed)
6220 /* Don't change the recorded last info after all, because we
6221 * haven't actually updated to the new info yet - we decided
6222 * to postpone our configure request until later.
6224 info->last = saved_last_info;
6226 gtk_widget_queue_resize_no_redraw (widget); /* migth recurse for GTK_RESIZE_IMMEDIATE */
6229 return; /* Bail out, we didn't really process the move/resize */
6231 else if ((configure_request_size_changed || hints_changed) &&
6232 (widget->allocation.width != new_request.width ||
6233 widget->allocation.height != new_request.height))
6236 /* We are in one of the following situations:
6237 * A. configure_request_size_changed
6238 * our requisition has changed and we need a different window size,
6239 * so we request it from the window manager.
6240 * B. !configure_request_size_changed && hints_changed
6241 * the window manager rejects our size, but we have just changed the
6242 * window manager hints, so there's a chance our request will
6243 * be honoured this time, so we try again.
6245 * However, if the new requisition is the same as the current allocation,
6246 * we don't request it again, since we won't get a ConfigureNotify back from
6247 * the window manager unless it decides to change our requisition. If
6248 * we don't get the ConfigureNotify back, the resize queue will never be run.
6251 /* Now send the configure request */
6252 if (configure_request_pos_changed)
6256 gdk_window_move_resize (window->frame,
6257 new_request.x - window->frame_left,
6258 new_request.y - window->frame_top,
6259 new_request.width + window->frame_left + window->frame_right,
6260 new_request.height + window->frame_top + window->frame_bottom);
6261 gdk_window_resize (widget->window,
6262 new_request.width, new_request.height);
6265 gdk_window_move_resize (widget->window,
6266 new_request.x, new_request.y,
6267 new_request.width, new_request.height);
6269 else /* only size changed */
6272 gdk_window_resize (window->frame,
6273 new_request.width + window->frame_left + window->frame_right,
6274 new_request.height + window->frame_top + window->frame_bottom);
6275 gdk_window_resize (widget->window,
6276 new_request.width, new_request.height);
6279 if (window->type == GTK_WINDOW_POPUP)
6281 GtkAllocation allocation;
6283 /* Directly size allocate for override redirect (popup) windows. */
6286 allocation.width = new_request.width;
6287 allocation.height = new_request.height;
6289 gtk_widget_size_allocate (widget, &allocation);
6291 gdk_window_process_updates (widget->window, TRUE);
6293 if (container->resize_mode == GTK_RESIZE_QUEUE)
6294 gtk_widget_queue_draw (widget);
6298 /* Increment the number of have-not-yet-received-notify requests */
6299 window->configure_request_count += 1;
6300 gdk_window_freeze_toplevel_updates_libgtk_only (widget->window);
6302 /* for GTK_RESIZE_QUEUE toplevels, we are now awaiting a new
6303 * configure event in response to our resizing request.
6304 * the configure event will cause a new resize with
6305 * ->configure_notify_received=TRUE.
6306 * until then, we want to
6307 * - discard expose events
6308 * - coalesce resizes for our children
6309 * - defer any window resizes until the configure event arrived
6310 * to achieve this, we queue a resize for the window, but remove its
6311 * resizing handler, so resizing will not be handled from the next
6312 * idle handler but when the configure event arrives.
6314 * FIXME: we should also dequeue the pending redraws here, since
6315 * we handle those ourselves upon ->configure_notify_received==TRUE.
6317 if (container->resize_mode == GTK_RESIZE_QUEUE)
6319 gtk_widget_queue_resize_no_redraw (widget);
6320 _gtk_container_dequeue_resize_handler (container);
6326 /* Handle any position changes.
6328 if (configure_request_pos_changed)
6332 gdk_window_move (window->frame,
6333 new_request.x - window->frame_left,
6334 new_request.y - window->frame_top);
6337 gdk_window_move (widget->window,
6338 new_request.x, new_request.y);
6341 /* And run the resize queue.
6343 gtk_container_resize_children (container);
6346 /* We have now processed a move/resize since the last position
6347 * constraint change, setting of the initial position, or resize.
6348 * (Not resetting these flags here can lead to infinite loops for
6349 * GTK_RESIZE_IMMEDIATE containers)
6351 info->position_constraints_changed = FALSE;
6352 info->initial_pos_set = FALSE;
6353 info->resize_width = -1;
6354 info->resize_height = -1;
6357 /* Compare two sets of Geometry hints for equality.
6360 gtk_window_compare_hints (GdkGeometry *geometry_a,
6362 GdkGeometry *geometry_b,
6365 if (flags_a != flags_b)
6368 if ((flags_a & GDK_HINT_MIN_SIZE) &&
6369 (geometry_a->min_width != geometry_b->min_width ||
6370 geometry_a->min_height != geometry_b->min_height))
6373 if ((flags_a & GDK_HINT_MAX_SIZE) &&
6374 (geometry_a->max_width != geometry_b->max_width ||
6375 geometry_a->max_height != geometry_b->max_height))
6378 if ((flags_a & GDK_HINT_BASE_SIZE) &&
6379 (geometry_a->base_width != geometry_b->base_width ||
6380 geometry_a->base_height != geometry_b->base_height))
6383 if ((flags_a & GDK_HINT_ASPECT) &&
6384 (geometry_a->min_aspect != geometry_b->min_aspect ||
6385 geometry_a->max_aspect != geometry_b->max_aspect))
6388 if ((flags_a & GDK_HINT_RESIZE_INC) &&
6389 (geometry_a->width_inc != geometry_b->width_inc ||
6390 geometry_a->height_inc != geometry_b->height_inc))
6393 if ((flags_a & GDK_HINT_WIN_GRAVITY) &&
6394 geometry_a->win_gravity != geometry_b->win_gravity)
6401 _gtk_window_constrain_size (GtkWindow *window,
6407 GtkWindowGeometryInfo *info;
6409 g_return_if_fail (GTK_IS_WINDOW (window));
6411 info = window->geometry_info;
6414 GdkWindowHints flags = info->last.flags;
6415 GdkGeometry *geometry = &info->last.geometry;
6417 gtk_window_constrain_size (window,
6428 gtk_window_constrain_size (GtkWindow *window,
6429 GdkGeometry *geometry,
6436 gdk_window_constrain_size (geometry, flags, width, height,
6437 new_width, new_height);
6440 /* Compute the set of geometry hints and flags for a window
6441 * based on the application set geometry, and requisiition
6442 * of the window. gtk_widget_size_request() must have been
6446 gtk_window_compute_hints (GtkWindow *window,
6447 GdkGeometry *new_geometry,
6451 gint extra_width = 0;
6452 gint extra_height = 0;
6453 GtkWindowGeometryInfo *geometry_info;
6454 GtkRequisition requisition;
6456 widget = GTK_WIDGET (window);
6458 gtk_widget_get_child_requisition (widget, &requisition);
6459 geometry_info = gtk_window_get_geometry_info (GTK_WINDOW (widget), FALSE);
6463 *new_flags = geometry_info->mask;
6464 *new_geometry = geometry_info->geometry;
6471 if (geometry_info && geometry_info->widget)
6473 GtkRequisition child_requisition;
6475 /* FIXME: This really isn't right. It gets the min size wrong and forces
6476 * callers to do horrible hacks like set a huge usize on the child requisition
6477 * to get the base size right. We really want to find the answers to:
6479 * - If the geometry widget was infinitely big, how much extra space
6480 * would be needed for the stuff around it.
6482 * - If the geometry widget was infinitely small, how big would the
6483 * window still have to be.
6485 * Finding these answers would be a bit of a mess here. (Bug #68668)
6487 gtk_widget_get_child_requisition (geometry_info->widget, &child_requisition);
6489 extra_width = widget->requisition.width - child_requisition.width;
6490 extra_height = widget->requisition.height - child_requisition.height;
6493 /* We don't want to set GDK_HINT_POS in here, we just set it
6494 * in gtk_window_move_resize() when we want the position
6498 if (*new_flags & GDK_HINT_BASE_SIZE)
6500 new_geometry->base_width += extra_width;
6501 new_geometry->base_height += extra_height;
6503 else if (!(*new_flags & GDK_HINT_MIN_SIZE) &&
6504 (*new_flags & GDK_HINT_RESIZE_INC) &&
6505 ((extra_width != 0) || (extra_height != 0)))
6507 *new_flags |= GDK_HINT_BASE_SIZE;
6509 new_geometry->base_width = extra_width;
6510 new_geometry->base_height = extra_height;
6513 if (*new_flags & GDK_HINT_MIN_SIZE)
6515 if (new_geometry->min_width < 0)
6516 new_geometry->min_width = requisition.width;
6518 new_geometry->min_width += extra_width;
6520 if (new_geometry->min_height < 0)
6521 new_geometry->min_height = requisition.height;
6523 new_geometry->min_height += extra_height;
6525 else if (!window->allow_shrink)
6527 *new_flags |= GDK_HINT_MIN_SIZE;
6529 new_geometry->min_width = requisition.width;
6530 new_geometry->min_height = requisition.height;
6533 if (*new_flags & GDK_HINT_MAX_SIZE)
6535 if (new_geometry->max_width < 0)
6536 new_geometry->max_width = requisition.width;
6538 new_geometry->max_width += extra_width;
6540 if (new_geometry->max_height < 0)
6541 new_geometry->max_height = requisition.height;
6543 new_geometry->max_height += extra_height;
6545 else if (!window->allow_grow)
6547 *new_flags |= GDK_HINT_MAX_SIZE;
6549 new_geometry->max_width = requisition.width;
6550 new_geometry->max_height = requisition.height;
6553 *new_flags |= GDK_HINT_WIN_GRAVITY;
6554 new_geometry->win_gravity = window->gravity;
6557 /***********************
6558 * Redrawing functions *
6559 ***********************/
6562 gtk_window_paint (GtkWidget *widget,
6565 gtk_paint_flat_box (widget->style, widget->window, GTK_STATE_NORMAL,
6566 GTK_SHADOW_NONE, area, widget, "base", 0, 0, -1, -1);
6570 gtk_window_expose (GtkWidget *widget,
6571 GdkEventExpose *event)
6573 if (!GTK_WIDGET_APP_PAINTABLE (widget))
6574 gtk_window_paint (widget, &event->area);
6576 if (GTK_WIDGET_CLASS (gtk_window_parent_class)->expose_event)
6577 return GTK_WIDGET_CLASS (gtk_window_parent_class)->expose_event (widget, event);
6583 * gtk_window_set_has_frame:
6584 * @window: a #GtkWindow
6585 * @setting: a boolean
6587 * (Note: this is a special-purpose function for the framebuffer port,
6588 * that causes GTK+ to draw its own window border. For most applications,
6589 * you want gtk_window_set_decorated() instead, which tells the window
6590 * manager whether to draw the window border.)
6592 * If this function is called on a window with setting of %TRUE, before
6593 * it is realized or showed, it will have a "frame" window around
6594 * @window->window, accessible in @window->frame. Using the signal
6595 * frame_event you can receive all events targeted at the frame.
6597 * This function is used by the linux-fb port to implement managed
6598 * windows, but it could conceivably be used by X-programs that
6599 * want to do their own window decorations.
6603 gtk_window_set_has_frame (GtkWindow *window,
6606 g_return_if_fail (GTK_IS_WINDOW (window));
6607 g_return_if_fail (!GTK_WIDGET_REALIZED (window));
6609 window->has_frame = setting != FALSE;
6613 * gtk_window_get_has_frame:
6614 * @window: a #GtkWindow
6616 * Accessor for whether the window has a frame window exterior to
6617 * @window->window. Gets the value set by gtk_window_set_has_frame ().
6619 * Return value: %TRUE if a frame has been added to the window
6620 * via gtk_window_set_has_frame().
6623 gtk_window_get_has_frame (GtkWindow *window)
6625 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
6627 return window->has_frame;
6631 * gtk_window_set_frame_dimensions:
6632 * @window: a #GtkWindow that has a frame
6633 * @left: The width of the left border
6634 * @top: The height of the top border
6635 * @right: The width of the right border
6636 * @bottom: The height of the bottom border
6638 * (Note: this is a special-purpose function intended for the framebuffer
6639 * port; see gtk_window_set_has_frame(). It will have no effect on the
6640 * window border drawn by the window manager, which is the normal
6641 * case when using the X Window system.)
6643 * For windows with frames (see gtk_window_set_has_frame()) this function
6644 * can be used to change the size of the frame border.
6647 gtk_window_set_frame_dimensions (GtkWindow *window,
6655 g_return_if_fail (GTK_IS_WINDOW (window));
6657 widget = GTK_WIDGET (window);
6659 if (window->frame_left == left &&
6660 window->frame_top == top &&
6661 window->frame_right == right &&
6662 window->frame_bottom == bottom)
6665 window->frame_left = left;
6666 window->frame_top = top;
6667 window->frame_right = right;
6668 window->frame_bottom = bottom;
6670 if (GTK_WIDGET_REALIZED (widget) && window->frame)
6672 gint width = widget->allocation.width + left + right;
6673 gint height = widget->allocation.height + top + bottom;
6674 gdk_window_resize (window->frame, width, height);
6675 gtk_decorated_window_move_resize_window (window,
6677 widget->allocation.width,
6678 widget->allocation.height);
6683 * gtk_window_present:
6684 * @window: a #GtkWindow
6686 * Presents a window to the user. This may mean raising the window
6687 * in the stacking order, deiconifying it, moving it to the current
6688 * desktop, and/or giving it the keyboard focus, possibly dependent
6689 * on the user's platform, window manager, and preferences.
6691 * If @window is hidden, this function calls gtk_widget_show()
6694 * This function should be used when the user tries to open a window
6695 * that's already open. Say for example the preferences dialog is
6696 * currently open, and the user chooses Preferences from the menu
6697 * a second time; use gtk_window_present() to move the already-open dialog
6698 * where the user can see it.
6700 * If you are calling this function in response to a user interaction,
6701 * it is preferable to use gtk_window_present_with_time().
6705 gtk_window_present (GtkWindow *window)
6707 gtk_window_present_with_time (window, GDK_CURRENT_TIME);
6711 * gtk_window_present_with_time:
6712 * @window: a #GtkWindow
6713 * @timestamp: the timestamp of the user interaction (typically a
6714 * button or key press event) which triggered this call
6716 * Presents a window to the user in response to a user interaction.
6717 * If you need to present a window without a timestamp, use
6718 * gtk_window_present(). See gtk_window_present() for details.
6723 gtk_window_present_with_time (GtkWindow *window,
6728 g_return_if_fail (GTK_IS_WINDOW (window));
6730 widget = GTK_WIDGET (window);
6732 if (GTK_WIDGET_VISIBLE (window))
6734 g_assert (widget->window != NULL);
6736 gdk_window_show (widget->window);
6738 /* Translate a timestamp of GDK_CURRENT_TIME appropriately */
6739 if (timestamp == GDK_CURRENT_TIME)
6741 #ifdef GDK_WINDOWING_X11
6742 GdkDisplay *display;
6744 display = gtk_widget_get_display (GTK_WIDGET (window));
6745 timestamp = gdk_x11_display_get_user_time (display);
6747 timestamp = gtk_get_current_event_time ();
6751 gdk_window_focus (widget->window, timestamp);
6755 gtk_widget_show (widget);
6760 * gtk_window_iconify:
6761 * @window: a #GtkWindow
6763 * Asks to iconify (i.e. minimize) the specified @window. Note that
6764 * you shouldn't assume the window is definitely iconified afterward,
6765 * because other entities (e.g. the user or <link
6766 * linkend="gtk-X11-arch">window manager</link>) could deiconify it
6767 * again, or there may not be a window manager in which case
6768 * iconification isn't possible, etc. But normally the window will end
6769 * up iconified. Just don't write code that crashes if not.
6771 * It's permitted to call this function before showing a window,
6772 * in which case the window will be iconified before it ever appears
6775 * You can track iconification via the "window-state-event" signal
6780 gtk_window_iconify (GtkWindow *window)
6783 GdkWindow *toplevel;
6785 g_return_if_fail (GTK_IS_WINDOW (window));
6787 widget = GTK_WIDGET (window);
6789 window->iconify_initially = TRUE;
6792 toplevel = window->frame;
6794 toplevel = widget->window;
6796 if (toplevel != NULL)
6797 gdk_window_iconify (toplevel);
6801 * gtk_window_deiconify:
6802 * @window: a #GtkWindow
6804 * Asks to deiconify (i.e. unminimize) the specified @window. Note
6805 * that you shouldn't assume the window is definitely deiconified
6806 * afterward, because other entities (e.g. the user or <link
6807 * linkend="gtk-X11-arch">window manager</link>) could iconify it
6808 * again before your code which assumes deiconification gets to run.
6810 * You can track iconification via the "window-state-event" signal
6814 gtk_window_deiconify (GtkWindow *window)
6817 GdkWindow *toplevel;
6819 g_return_if_fail (GTK_IS_WINDOW (window));
6821 widget = GTK_WIDGET (window);
6823 window->iconify_initially = FALSE;
6826 toplevel = window->frame;
6828 toplevel = widget->window;
6830 if (toplevel != NULL)
6831 gdk_window_deiconify (toplevel);
6836 * @window: a #GtkWindow
6838 * Asks to stick @window, which means that it will appear on all user
6839 * desktops. Note that you shouldn't assume the window is definitely
6840 * stuck afterward, because other entities (e.g. the user or <link
6841 * linkend="gtk-X11-arch">window manager</link>) could unstick it
6842 * again, and some window managers do not support sticking
6843 * windows. But normally the window will end up stuck. Just don't
6844 * write code that crashes if not.
6846 * It's permitted to call this function before showing a window.
6848 * You can track stickiness via the "window-state-event" signal
6853 gtk_window_stick (GtkWindow *window)
6856 GdkWindow *toplevel;
6858 g_return_if_fail (GTK_IS_WINDOW (window));
6860 widget = GTK_WIDGET (window);
6862 window->stick_initially = TRUE;
6865 toplevel = window->frame;
6867 toplevel = widget->window;
6869 if (toplevel != NULL)
6870 gdk_window_stick (toplevel);
6874 * gtk_window_unstick:
6875 * @window: a #GtkWindow
6877 * Asks to unstick @window, which means that it will appear on only
6878 * one of the user's desktops. Note that you shouldn't assume the
6879 * window is definitely unstuck afterward, because other entities
6880 * (e.g. the user or <link linkend="gtk-X11-arch">window
6881 * manager</link>) could stick it again. But normally the window will
6882 * end up stuck. Just don't write code that crashes if not.
6884 * You can track stickiness via the "window-state-event" signal
6889 gtk_window_unstick (GtkWindow *window)
6892 GdkWindow *toplevel;
6894 g_return_if_fail (GTK_IS_WINDOW (window));
6896 widget = GTK_WIDGET (window);
6898 window->stick_initially = FALSE;
6901 toplevel = window->frame;
6903 toplevel = widget->window;
6905 if (toplevel != NULL)
6906 gdk_window_unstick (toplevel);
6910 * gtk_window_maximize:
6911 * @window: a #GtkWindow
6913 * Asks to maximize @window, so that it becomes full-screen. Note that
6914 * you shouldn't assume the window is definitely maximized afterward,
6915 * because other entities (e.g. the user or <link
6916 * linkend="gtk-X11-arch">window manager</link>) could unmaximize it
6917 * again, and not all window managers support maximization. But
6918 * normally the window will end up maximized. Just don't write code
6919 * that crashes if not.
6921 * It's permitted to call this function before showing a window,
6922 * in which case the window will be maximized when it appears onscreen
6925 * You can track maximization via the "window-state-event" signal
6930 gtk_window_maximize (GtkWindow *window)
6933 GdkWindow *toplevel;
6935 g_return_if_fail (GTK_IS_WINDOW (window));
6937 widget = GTK_WIDGET (window);
6939 window->maximize_initially = TRUE;
6942 toplevel = window->frame;
6944 toplevel = widget->window;
6946 if (toplevel != NULL)
6947 gdk_window_maximize (toplevel);
6951 * gtk_window_unmaximize:
6952 * @window: a #GtkWindow
6954 * Asks to unmaximize @window. Note that you shouldn't assume the
6955 * window is definitely unmaximized afterward, because other entities
6956 * (e.g. the user or <link linkend="gtk-X11-arch">window
6957 * manager</link>) could maximize it again, and not all window
6958 * managers honor requests to unmaximize. But normally the window will
6959 * end up unmaximized. Just don't write code that crashes if not.
6961 * You can track maximization via the "window-state-event" signal
6966 gtk_window_unmaximize (GtkWindow *window)
6969 GdkWindow *toplevel;
6971 g_return_if_fail (GTK_IS_WINDOW (window));
6973 widget = GTK_WIDGET (window);
6975 window->maximize_initially = FALSE;
6978 toplevel = window->frame;
6980 toplevel = widget->window;
6982 if (toplevel != NULL)
6983 gdk_window_unmaximize (toplevel);
6987 * gtk_window_fullscreen:
6988 * @window: a #GtkWindow
6990 * Asks to place @window in the fullscreen state. Note that you
6991 * shouldn't assume the window is definitely full screen afterward,
6992 * because other entities (e.g. the user or <link
6993 * linkend="gtk-X11-arch">window manager</link>) could unfullscreen it
6994 * again, and not all window managers honor requests to fullscreen
6995 * windows. But normally the window will end up fullscreen. Just
6996 * don't write code that crashes if not.
6998 * You can track the fullscreen state via the "window-state-event" signal
7004 gtk_window_fullscreen (GtkWindow *window)
7007 GdkWindow *toplevel;
7008 GtkWindowPrivate *priv;
7010 g_return_if_fail (GTK_IS_WINDOW (window));
7012 widget = GTK_WIDGET (window);
7013 priv = GTK_WINDOW_GET_PRIVATE (window);
7015 priv->fullscreen_initially = TRUE;
7018 toplevel = window->frame;
7020 toplevel = widget->window;
7022 if (toplevel != NULL)
7023 gdk_window_fullscreen (toplevel);
7027 * gtk_window_unfullscreen:
7028 * @window: a #GtkWindow
7030 * Asks to toggle off the fullscreen state for @window. Note that you
7031 * shouldn't assume the window is definitely not full screen
7032 * afterward, because other entities (e.g. the user or <link
7033 * linkend="gtk-X11-arch">window manager</link>) could fullscreen it
7034 * again, and not all window managers honor requests to unfullscreen
7035 * windows. But normally the window will end up restored to its normal
7036 * state. Just don't write code that crashes if not.
7038 * You can track the fullscreen state via the "window-state-event" signal
7044 gtk_window_unfullscreen (GtkWindow *window)
7047 GdkWindow *toplevel;
7048 GtkWindowPrivate *priv;
7050 g_return_if_fail (GTK_IS_WINDOW (window));
7052 widget = GTK_WIDGET (window);
7053 priv = GTK_WINDOW_GET_PRIVATE (window);
7055 priv->fullscreen_initially = FALSE;
7058 toplevel = window->frame;
7060 toplevel = widget->window;
7062 if (toplevel != NULL)
7063 gdk_window_unfullscreen (toplevel);
7067 * gtk_window_set_keep_above:
7068 * @window: a #GtkWindow
7069 * @setting: whether to keep @window above other windows
7071 * Asks to keep @window above, so that it stays on top. Note that
7072 * you shouldn't assume the window is definitely above afterward,
7073 * because other entities (e.g. the user or <link
7074 * linkend="gtk-X11-arch">window manager</link>) could not keep it above,
7075 * and not all window managers support keeping windows above. But
7076 * normally the window will end kept above. Just don't write code
7077 * that crashes if not.
7079 * It's permitted to call this function before showing a window,
7080 * in which case the window will be kept above when it appears onscreen
7083 * You can track the above state via the "window-state-event" signal
7086 * Note that, according to the <ulink
7087 * url="http://www.freedesktop.org/Standards/wm-spec">Extended Window
7088 * Manager Hints</ulink> specification, the above state is mainly meant
7089 * for user preferences and should not be used by applications e.g. for
7090 * drawing attention to their dialogs.
7095 gtk_window_set_keep_above (GtkWindow *window,
7099 GtkWindowPrivate *priv;
7100 GdkWindow *toplevel;
7102 g_return_if_fail (GTK_IS_WINDOW (window));
7104 widget = GTK_WIDGET (window);
7105 priv = GTK_WINDOW_GET_PRIVATE (window);
7107 priv->above_initially = setting != FALSE;
7109 priv->below_initially = FALSE;
7112 toplevel = window->frame;
7114 toplevel = widget->window;
7116 if (toplevel != NULL)
7117 gdk_window_set_keep_above (toplevel, setting);
7121 * gtk_window_set_keep_below:
7122 * @window: a #GtkWindow
7123 * @setting: whether to keep @window below other windows
7125 * Asks to keep @window below, so that it stays in bottom. Note that
7126 * you shouldn't assume the window is definitely below afterward,
7127 * because other entities (e.g. the user or <link
7128 * linkend="gtk-X11-arch">window manager</link>) could not keep it below,
7129 * and not all window managers support putting windows below. But
7130 * normally the window will be kept below. Just don't write code
7131 * that crashes if not.
7133 * It's permitted to call this function before showing a window,
7134 * in which case the window will be kept below when it appears onscreen
7137 * You can track the below state via the "window-state-event" signal
7140 * Note that, according to the <ulink
7141 * url="http://www.freedesktop.org/Standards/wm-spec">Extended Window
7142 * Manager Hints</ulink> specification, the above state is mainly meant
7143 * for user preferences and should not be used by applications e.g. for
7144 * drawing attention to their dialogs.
7149 gtk_window_set_keep_below (GtkWindow *window,
7153 GtkWindowPrivate *priv;
7154 GdkWindow *toplevel;
7156 g_return_if_fail (GTK_IS_WINDOW (window));
7158 widget = GTK_WIDGET (window);
7159 priv = GTK_WINDOW_GET_PRIVATE (window);
7161 priv->below_initially = setting != FALSE;
7163 priv->above_initially = FALSE;
7166 toplevel = window->frame;
7168 toplevel = widget->window;
7170 if (toplevel != NULL)
7171 gdk_window_set_keep_below (toplevel, setting);
7175 * gtk_window_set_resizable:
7176 * @window: a #GtkWindow
7177 * @resizable: %TRUE if the user can resize this window
7179 * Sets whether the user can resize a window. Windows are user resizable
7183 gtk_window_set_resizable (GtkWindow *window,
7186 g_return_if_fail (GTK_IS_WINDOW (window));
7188 gtk_window_set_policy_internal (window, FALSE, resizable, FALSE);
7192 * gtk_window_get_resizable:
7193 * @window: a #GtkWindow
7195 * Gets the value set by gtk_window_set_resizable().
7197 * Return value: %TRUE if the user can resize the window
7200 gtk_window_get_resizable (GtkWindow *window)
7202 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
7204 /* allow_grow is most likely to indicate the semantic concept we
7205 * mean by "resizable" (and will be a reliable indicator if
7206 * set_policy() hasn't been called)
7208 return window->allow_grow;
7212 * gtk_window_set_gravity:
7213 * @window: a #GtkWindow
7214 * @gravity: window gravity
7216 * Window gravity defines the meaning of coordinates passed to
7217 * gtk_window_move(). See gtk_window_move() and #GdkGravity for
7220 * The default window gravity is #GDK_GRAVITY_NORTH_WEST which will
7221 * typically "do what you mean."
7225 gtk_window_set_gravity (GtkWindow *window,
7228 g_return_if_fail (GTK_IS_WINDOW (window));
7230 if (gravity != window->gravity)
7232 window->gravity = gravity;
7234 /* gtk_window_move_resize() will adapt gravity
7236 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
7238 g_object_notify (G_OBJECT (window), "gravity");
7243 * gtk_window_get_gravity:
7244 * @window: a #GtkWindow
7246 * Gets the value set by gtk_window_set_gravity().
7248 * Return value: window gravity
7251 gtk_window_get_gravity (GtkWindow *window)
7253 g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
7255 return window->gravity;
7259 * gtk_window_begin_resize_drag:
7260 * @window: a #GtkWindow
7261 * @button: mouse button that initiated the drag
7262 * @edge: position of the resize control
7263 * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
7264 * @root_y: Y position where the user clicked to initiate the drag
7265 * @timestamp: timestamp from the click event that initiated the drag
7267 * Starts resizing a window. This function is used if an application
7268 * has window resizing controls. When GDK can support it, the resize
7269 * will be done using the standard mechanism for the <link
7270 * linkend="gtk-X11-arch">window manager</link> or windowing
7271 * system. Otherwise, GDK will try to emulate window resizing,
7272 * potentially not all that well, depending on the windowing system.
7276 gtk_window_begin_resize_drag (GtkWindow *window,
7284 GdkWindow *toplevel;
7286 g_return_if_fail (GTK_IS_WINDOW (window));
7287 g_return_if_fail (GTK_WIDGET_VISIBLE (window));
7289 widget = GTK_WIDGET (window);
7292 toplevel = window->frame;
7294 toplevel = widget->window;
7296 gdk_window_begin_resize_drag (toplevel,
7303 * gtk_window_get_frame_dimensions:
7304 * @window: a #GtkWindow
7305 * @left: location to store the width of the frame at the left, or %NULL
7306 * @top: location to store the height of the frame at the top, or %NULL
7307 * @right: location to store the width of the frame at the returns, or %NULL
7308 * @bottom: location to store the height of the frame at the bottom, or %NULL
7310 * (Note: this is a special-purpose function intended for the
7311 * framebuffer port; see gtk_window_set_has_frame(). It will not
7312 * return the size of the window border drawn by the <link
7313 * linkend="gtk-X11-arch">window manager</link>, which is the normal
7314 * case when using a windowing system. See
7315 * gdk_window_get_frame_extents() to get the standard window border
7318 * Retrieves the dimensions of the frame window for this toplevel.
7319 * See gtk_window_set_has_frame(), gtk_window_set_frame_dimensions().
7322 gtk_window_get_frame_dimensions (GtkWindow *window,
7328 g_return_if_fail (GTK_IS_WINDOW (window));
7331 *left = window->frame_left;
7333 *top = window->frame_top;
7335 *right = window->frame_right;
7337 *bottom = window->frame_bottom;
7341 * gtk_window_begin_move_drag:
7342 * @window: a #GtkWindow
7343 * @button: mouse button that initiated the drag
7344 * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
7345 * @root_y: Y position where the user clicked to initiate the drag
7346 * @timestamp: timestamp from the click event that initiated the drag
7348 * Starts moving a window. This function is used if an application has
7349 * window movement grips. When GDK can support it, the window movement
7350 * will be done using the standard mechanism for the <link
7351 * linkend="gtk-X11-arch">window manager</link> or windowing
7352 * system. Otherwise, GDK will try to emulate window movement,
7353 * potentially not all that well, depending on the windowing system.
7357 gtk_window_begin_move_drag (GtkWindow *window,
7364 GdkWindow *toplevel;
7366 g_return_if_fail (GTK_IS_WINDOW (window));
7367 g_return_if_fail (GTK_WIDGET_VISIBLE (window));
7369 widget = GTK_WIDGET (window);
7372 toplevel = window->frame;
7374 toplevel = widget->window;
7376 gdk_window_begin_move_drag (toplevel,
7383 * gtk_window_set_screen:
7384 * @window: a #GtkWindow.
7385 * @screen: a #GdkScreen.
7387 * Sets the #GdkScreen where the @window is displayed; if
7388 * the window is already mapped, it will be unmapped, and
7389 * then remapped on the new screen.
7394 gtk_window_set_screen (GtkWindow *window,
7398 GdkScreen *previous_screen;
7399 gboolean was_mapped;
7401 g_return_if_fail (GTK_IS_WINDOW (window));
7402 g_return_if_fail (GDK_IS_SCREEN (screen));
7404 if (screen == window->screen)
7407 widget = GTK_WIDGET (window);
7409 previous_screen = window->screen;
7410 was_mapped = GTK_WIDGET_MAPPED (widget);
7413 gtk_widget_unmap (widget);
7414 if (GTK_WIDGET_REALIZED (widget))
7415 gtk_widget_unrealize (widget);
7417 gtk_window_free_key_hash (window);
7418 window->screen = screen;
7419 gtk_widget_reset_rc_styles (widget);
7420 if (screen != previous_screen)
7422 g_signal_handlers_disconnect_by_func (previous_screen,
7423 gtk_window_on_composited_changed, window);
7424 g_signal_connect (screen, "composited-changed",
7425 G_CALLBACK (gtk_window_on_composited_changed), window);
7427 _gtk_widget_propagate_screen_changed (widget, previous_screen);
7428 _gtk_widget_propagate_composited_changed (widget);
7430 g_object_notify (G_OBJECT (window), "screen");
7433 gtk_widget_map (widget);
7437 gtk_window_on_composited_changed (GdkScreen *screen,
7440 gtk_widget_queue_draw (GTK_WIDGET (window));
7442 _gtk_widget_propagate_composited_changed (GTK_WIDGET (window));
7446 gtk_window_check_screen (GtkWindow *window)
7449 return window->screen;
7452 g_warning ("Screen for GtkWindow not set; you must always set\n"
7453 "a screen for a GtkWindow before using the window");
7459 * gtk_window_get_screen:
7460 * @window: a #GtkWindow.
7462 * Returns the #GdkScreen associated with @window.
7464 * Return value: a #GdkScreen.
7469 gtk_window_get_screen (GtkWindow *window)
7471 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
7473 return window->screen;
7477 * gtk_window_is_active:
7478 * @window: a #GtkWindow
7480 * Returns whether the window is part of the current active toplevel.
7481 * (That is, the toplevel window receiving keystrokes.)
7482 * The return value is %TRUE if the window is active toplevel
7483 * itself, but also if it is, say, a #GtkPlug embedded in the active toplevel.
7484 * You might use this function if you wanted to draw a widget
7485 * differently in an active window from a widget in an inactive window.
7486 * See gtk_window_has_toplevel_focus()
7488 * Return value: %TRUE if the window part of the current active window.
7493 gtk_window_is_active (GtkWindow *window)
7495 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
7497 return window->is_active;
7501 * gtk_window_has_toplevel_focus:
7502 * @window: a #GtkWindow
7504 * Returns whether the input focus is within this GtkWindow.
7505 * For real toplevel windows, this is identical to gtk_window_is_active(),
7506 * but for embedded windows, like #GtkPlug, the results will differ.
7508 * Return value: %TRUE if the input focus is within this GtkWindow
7513 gtk_window_has_toplevel_focus (GtkWindow *window)
7515 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
7517 return window->has_toplevel_focus;
7521 gtk_window_group_class_init (GtkWindowGroupClass *klass)
7526 gtk_window_group_get_type (void)
7528 static GType window_group_type = 0;
7530 if (!window_group_type)
7532 const GTypeInfo window_group_info =
7534 sizeof (GtkWindowGroupClass),
7535 NULL, /* base_init */
7536 NULL, /* base_finalize */
7537 (GClassInitFunc) gtk_window_group_class_init,
7538 NULL, /* class_finalize */
7539 NULL, /* class_data */
7540 sizeof (GtkWindowGroup),
7541 0, /* n_preallocs */
7542 (GInstanceInitFunc) NULL,
7545 window_group_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkWindowGroup"),
7546 &window_group_info, 0);
7549 return window_group_type;
7553 * gtk_window_group_new:
7555 * Creates a new #GtkWindowGroup object. Grabs added with
7556 * gtk_grab_add() only affect windows within the same #GtkWindowGroup.
7558 * Return value: a new #GtkWindowGroup.
7561 gtk_window_group_new (void)
7563 return g_object_new (GTK_TYPE_WINDOW_GROUP, NULL);
7567 window_group_cleanup_grabs (GtkWindowGroup *group,
7571 GSList *to_remove = NULL;
7573 tmp_list = group->grabs;
7576 if (gtk_widget_get_toplevel (tmp_list->data) == (GtkWidget*) window)
7577 to_remove = g_slist_prepend (to_remove, g_object_ref (tmp_list->data));
7578 tmp_list = tmp_list->next;
7583 gtk_grab_remove (to_remove->data);
7584 g_object_unref (to_remove->data);
7585 to_remove = g_slist_delete_link (to_remove, to_remove);
7590 * gtk_window_group_add_window:
7591 * @window_group: a #GtkWindowGroup
7592 * @window: the #GtkWindow to add
7594 * Adds a window to a #GtkWindowGroup.
7597 gtk_window_group_add_window (GtkWindowGroup *window_group,
7600 g_return_if_fail (GTK_IS_WINDOW_GROUP (window_group));
7601 g_return_if_fail (GTK_IS_WINDOW (window));
7603 if (window->group != window_group)
7605 g_object_ref (window);
7606 g_object_ref (window_group);
7609 gtk_window_group_remove_window (window->group, window);
7611 window_group_cleanup_grabs (gtk_window_get_group (NULL), window);
7613 window->group = window_group;
7615 g_object_unref (window);
7620 * gtk_window_group_remove_window:
7621 * @window_group: a #GtkWindowGroup
7622 * @window: the #GtkWindow to remove
7624 * Removes a window from a #GtkWindowGroup.
7627 gtk_window_group_remove_window (GtkWindowGroup *window_group,
7630 g_return_if_fail (GTK_IS_WINDOW_GROUP (window_group));
7631 g_return_if_fail (GTK_IS_WINDOW (window));
7632 g_return_if_fail (window->group == window_group);
7634 g_object_ref (window);
7636 window_group_cleanup_grabs (window_group, window);
7637 window->group = NULL;
7639 g_object_unref (window_group);
7640 g_object_unref (window);
7644 * gtk_window_group_list_windows:
7645 * @window_group: a #GtkWindowGroup
7647 * Returns a list of the #GtkWindows that belong to @window_group.
7649 * Returns: A newly-allocated list of windows inside the group.
7654 gtk_window_group_list_windows (GtkWindowGroup *window_group)
7656 GList *toplevels, *toplevel, *group_windows;
7658 g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
7660 group_windows = NULL;
7661 toplevels = gtk_window_list_toplevels ();
7663 for (toplevel = toplevels; toplevel; toplevel = toplevel->next)
7665 GtkWindow *window = toplevel->data;
7667 if (window_group == window->group)
7668 group_windows = g_list_prepend (group_windows, window);
7671 return g_list_reverse (group_windows);
7675 * gtk_window_get_group:
7676 * @window: a #GtkWindow, or %NULL
7678 * Returns the group for @window or the default group, if
7679 * @window is %NULL or if @window does not have an explicit
7682 * Returns: the #GtkWindowGroup for a window or the default group
7687 gtk_window_get_group (GtkWindow *window)
7689 if (window && window->group)
7690 return window->group;
7693 static GtkWindowGroup *default_group = NULL;
7696 default_group = gtk_window_group_new ();
7698 return default_group;
7702 /* Return the current grab widget of the given group
7705 _gtk_window_group_get_current_grab (GtkWindowGroup *window_group)
7707 if (window_group->grabs)
7708 return GTK_WIDGET (window_group->grabs->data);
7713 Derived from XParseGeometry() in XFree86
7715 Copyright 1985, 1986, 1987,1998 The Open Group
7717 All Rights Reserved.
7719 The above copyright notice and this permission notice shall be included
7720 in all copies or substantial portions of the Software.
7722 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
7723 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
7724 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7725 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
7726 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
7727 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
7728 OTHER DEALINGS IN THE SOFTWARE.
7730 Except as contained in this notice, the name of The Open Group shall
7731 not be used in advertising or otherwise to promote the sale, use or
7732 other dealings in this Software without prior written authorization
7733 from The Open Group.
7738 * XParseGeometry parses strings of the form
7739 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
7740 * width, height, xoffset, and yoffset are unsigned integers.
7741 * Example: "=80x24+300-49"
7742 * The equal sign is optional.
7743 * It returns a bitmask that indicates which of the four values
7744 * were actually found in the string. For each value found,
7745 * the corresponding argument is updated; for each value
7746 * not found, the corresponding argument is left unchanged.
7749 /* The following code is from Xlib, and is minimally modified, so we
7750 * can track any upstream changes if required. Don't change this
7751 * code. Or if you do, put in a huge comment marking which thing
7756 read_int (gchar *string,
7764 else if (*string == '-')
7770 for (; (*string >= '0') && (*string <= '9'); string++)
7772 result = (result * 10) + (*string - '0');
7784 * Bitmask returned by XParseGeometry(). Each bit tells if the corresponding
7785 * value (x, y, width, height) was found in the parsed string.
7787 #define NoValue 0x0000
7788 #define XValue 0x0001
7789 #define YValue 0x0002
7790 #define WidthValue 0x0004
7791 #define HeightValue 0x0008
7792 #define AllValues 0x000F
7793 #define XNegative 0x0010
7794 #define YNegative 0x0020
7796 /* Try not to reformat/modify, so we can compare/sync with X sources */
7798 gtk_XParseGeometry (const char *string,
7801 unsigned int *width,
7802 unsigned int *height)
7806 unsigned int tempWidth, tempHeight;
7808 char *nextCharacter;
7810 /* These initializations are just to silence gcc */
7816 if ( (string == NULL) || (*string == '\0')) return(mask);
7818 string++; /* ignore possible '=' at beg of geometry spec */
7820 strind = (char *)string;
7821 if (*strind != '+' && *strind != '-' && *strind != 'x') {
7822 tempWidth = read_int(strind, &nextCharacter);
7823 if (strind == nextCharacter)
7825 strind = nextCharacter;
7829 if (*strind == 'x' || *strind == 'X') {
7831 tempHeight = read_int(strind, &nextCharacter);
7832 if (strind == nextCharacter)
7834 strind = nextCharacter;
7835 mask |= HeightValue;
7838 if ((*strind == '+') || (*strind == '-')) {
7839 if (*strind == '-') {
7841 tempX = -read_int(strind, &nextCharacter);
7842 if (strind == nextCharacter)
7844 strind = nextCharacter;
7850 tempX = read_int(strind, &nextCharacter);
7851 if (strind == nextCharacter)
7853 strind = nextCharacter;
7856 if ((*strind == '+') || (*strind == '-')) {
7857 if (*strind == '-') {
7859 tempY = -read_int(strind, &nextCharacter);
7860 if (strind == nextCharacter)
7862 strind = nextCharacter;
7869 tempY = read_int(strind, &nextCharacter);
7870 if (strind == nextCharacter)
7872 strind = nextCharacter;
7878 /* If strind isn't at the end of the string the it's an invalid
7879 geometry specification. */
7881 if (*strind != '\0') return (0);
7887 if (mask & WidthValue)
7889 if (mask & HeightValue)
7890 *height = tempHeight;
7895 * gtk_window_parse_geometry:
7896 * @window: a #GtkWindow
7897 * @geometry: geometry string
7899 * Parses a standard X Window System geometry string - see the
7900 * manual page for X (type 'man X') for details on this.
7901 * gtk_window_parse_geometry() does work on all GTK+ ports
7902 * including Win32 but is primarily intended for an X environment.
7904 * If either a size or a position can be extracted from the
7905 * geometry string, gtk_window_parse_geometry() returns %TRUE
7906 * and calls gtk_window_set_default_size() and/or gtk_window_move()
7907 * to resize/move the window.
7909 * If gtk_window_parse_geometry() returns %TRUE, it will also
7910 * set the #GDK_HINT_USER_POS and/or #GDK_HINT_USER_SIZE hints
7911 * indicating to the window manager that the size/position of
7912 * the window was user-specified. This causes most window
7913 * managers to honor the geometry.
7915 * Note that for gtk_window_parse_geometry() to work as expected, it has
7916 * to be called when the window has its "final" size, i.e. after calling
7917 * gtk_widget_show_all() on the contents and gtk_window_set_geometry_hints()
7920 * #include <gtk/gtk.h>
7923 * fill_with_content (GtkWidget *vbox)
7925 * /* fill with content... */
7929 * main (int argc, char *argv[])
7931 * GtkWidget *window, *vbox;
7932 * GdkGeometry size_hints = {
7933 * 100, 50, 0, 0, 100, 50, 10, 10, 0.0, 0.0, GDK_GRAVITY_NORTH_WEST
7936 * gtk_init (&argc, &argv);
7938 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
7939 * vbox = gtk_vbox_new (FALSE, 0);
7941 * gtk_container_add (GTK_CONTAINER (window), vbox);
7942 * fill_with_content (vbox);
7943 * gtk_widget_show_all (vbox);
7945 * gtk_window_set_geometry_hints (GTK_WINDOW (window),
7948 * GDK_HINT_MIN_SIZE |
7949 * GDK_HINT_BASE_SIZE |
7950 * GDK_HINT_RESIZE_INC);
7954 * if (!gtk_window_parse_geometry (GTK_WINDOW (window), argv[1]))
7955 * fprintf (stderr, "Failed to parse '%s'\n", argv[1]);
7958 * gtk_widget_show_all (window);
7965 * Return value: %TRUE if string was parsed successfully
7968 gtk_window_parse_geometry (GtkWindow *window,
7969 const gchar *geometry)
7971 gint result, x = 0, y = 0;
7974 gboolean size_set, pos_set;
7977 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
7978 g_return_val_if_fail (geometry != NULL, FALSE);
7980 screen = gtk_window_check_screen (window);
7982 result = gtk_XParseGeometry (geometry, &x, &y, &w, &h);
7985 if ((result & WidthValue) || (result & HeightValue))
7987 gtk_window_set_default_size_internal (window,
7988 TRUE, result & WidthValue ? w : -1,
7989 TRUE, result & HeightValue ? h : -1,
7994 gtk_window_get_size (window, (gint *)&w, (gint *)&h);
7996 grav = GDK_GRAVITY_NORTH_WEST;
7998 if ((result & XNegative) && (result & YNegative))
7999 grav = GDK_GRAVITY_SOUTH_EAST;
8000 else if (result & XNegative)
8001 grav = GDK_GRAVITY_NORTH_EAST;
8002 else if (result & YNegative)
8003 grav = GDK_GRAVITY_SOUTH_WEST;
8005 if ((result & XValue) == 0)
8008 if ((result & YValue) == 0)
8011 if (grav == GDK_GRAVITY_SOUTH_WEST ||
8012 grav == GDK_GRAVITY_SOUTH_EAST)
8013 y = gdk_screen_get_height (screen) - h + y;
8015 if (grav == GDK_GRAVITY_SOUTH_EAST ||
8016 grav == GDK_GRAVITY_NORTH_EAST)
8017 x = gdk_screen_get_width (screen) - w + x;
8019 /* we don't let you put a window offscreen; maybe some people would
8020 * prefer to be able to, but it's kind of a bogus thing to do.
8029 if ((result & XValue) || (result & YValue))
8031 gtk_window_set_gravity (window, grav);
8032 gtk_window_move (window, x, y);
8036 if (size_set || pos_set)
8038 /* Set USSize, USPosition hints */
8039 GtkWindowGeometryInfo *info;
8041 info = gtk_window_get_geometry_info (window, TRUE);
8044 info->mask |= GDK_HINT_USER_POS;
8046 info->mask |= GDK_HINT_USER_SIZE;
8053 gtk_window_mnemonic_hash_foreach (guint keyval,
8059 GtkWindowKeysForeachFunc func;
8063 (*info->func) (info->window, keyval, info->window->mnemonic_modifier, TRUE, info->func_data);
8067 _gtk_window_keys_foreach (GtkWindow *window,
8068 GtkWindowKeysForeachFunc func,
8072 GtkMnemonicHash *mnemonic_hash;
8076 GtkWindowKeysForeachFunc func;
8080 info.window = window;
8082 info.func_data = func_data;
8084 mnemonic_hash = gtk_window_get_mnemonic_hash (window, FALSE);
8086 _gtk_mnemonic_hash_foreach (mnemonic_hash,
8087 gtk_window_mnemonic_hash_foreach, &info);
8089 groups = gtk_accel_groups_from_object (G_OBJECT (window));
8092 GtkAccelGroup *group = groups->data;
8095 for (i = 0; i < group->n_accels; i++)
8097 GtkAccelKey *key = &group->priv_accels[i].key;
8100 (*func) (window, key->accel_key, key->accel_mods, FALSE, func_data);
8103 groups = groups->next;
8108 gtk_window_keys_changed (GtkWindow *window)
8110 gtk_window_free_key_hash (window);
8111 gtk_window_get_key_hash (window);
8114 typedef struct _GtkWindowKeyEntry GtkWindowKeyEntry;
8116 struct _GtkWindowKeyEntry
8120 guint is_mnemonic : 1;
8124 window_key_entry_destroy (gpointer data)
8126 g_slice_free (GtkWindowKeyEntry, data);
8130 add_to_key_hash (GtkWindow *window,
8132 GdkModifierType modifiers,
8133 gboolean is_mnemonic,
8136 GtkKeyHash *key_hash = data;
8138 GtkWindowKeyEntry *entry = g_slice_new (GtkWindowKeyEntry);
8140 entry->keyval = keyval;
8141 entry->modifiers = modifiers;
8142 entry->is_mnemonic = is_mnemonic;
8144 /* GtkAccelGroup stores lowercased accelerators. To deal
8145 * with this, if <Shift> was specified, uppercase.
8147 if (modifiers & GDK_SHIFT_MASK)
8149 if (keyval == GDK_Tab)
8150 keyval = GDK_ISO_Left_Tab;
8152 keyval = gdk_keyval_to_upper (keyval);
8155 _gtk_key_hash_add_entry (key_hash, keyval, entry->modifiers, entry);
8159 gtk_window_get_key_hash (GtkWindow *window)
8161 GdkScreen *screen = gtk_window_check_screen (window);
8162 GtkKeyHash *key_hash = g_object_get_qdata (G_OBJECT (window), quark_gtk_window_key_hash);
8167 key_hash = _gtk_key_hash_new (gdk_keymap_get_for_display (gdk_screen_get_display (screen)),
8168 (GDestroyNotify)window_key_entry_destroy);
8169 _gtk_window_keys_foreach (window, add_to_key_hash, key_hash);
8170 g_object_set_qdata (G_OBJECT (window), quark_gtk_window_key_hash, key_hash);
8176 gtk_window_free_key_hash (GtkWindow *window)
8178 GtkKeyHash *key_hash = g_object_get_qdata (G_OBJECT (window), quark_gtk_window_key_hash);
8181 _gtk_key_hash_free (key_hash);
8182 g_object_set_qdata (G_OBJECT (window), quark_gtk_window_key_hash, NULL);
8187 * gtk_window_activate_key:
8188 * @window: a #GtkWindow
8189 * @event: a #GdkEventKey
8191 * Activates mnemonics and accelerators for this #GtkWindow. This is normally
8192 * called by the default ::key_press_event handler for toplevel windows,
8193 * however in some cases it may be useful to call this directly when
8194 * overriding the standard key handling for a toplevel window.
8196 * Return value: %TRUE if a mnemonic or accelerator was found and activated.
8199 gtk_window_activate_key (GtkWindow *window,
8202 GtkKeyHash *key_hash;
8203 GtkWindowKeyEntry *found_entry = NULL;
8204 gboolean enable_mnemonics;
8205 gboolean enable_accels;
8207 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
8208 g_return_val_if_fail (event != NULL, FALSE);
8210 key_hash = gtk_window_get_key_hash (window);
8215 GSList *entries = _gtk_key_hash_lookup (key_hash,
8216 event->hardware_keycode,
8218 gtk_accelerator_get_default_mod_mask (),
8221 g_object_get (gtk_widget_get_settings (GTK_WIDGET (window)),
8222 "gtk-enable-mnemonics", &enable_mnemonics,
8223 "gtk-enable-accels", &enable_accels,
8226 for (tmp_list = entries; tmp_list; tmp_list = tmp_list->next)
8228 GtkWindowKeyEntry *entry = tmp_list->data;
8229 if (entry->is_mnemonic)
8231 if (enable_mnemonics)
8233 found_entry = entry;
8239 if (enable_accels && !found_entry)
8241 found_entry = entry;
8246 g_slist_free (entries);
8251 if (found_entry->is_mnemonic)
8253 if (enable_mnemonics)
8254 return gtk_window_mnemonic_activate (window, found_entry->keyval,
8255 found_entry->modifiers);
8260 return gtk_accel_groups_activate (G_OBJECT (window), found_entry->keyval,
8261 found_entry->modifiers);
8269 window_update_has_focus (GtkWindow *window)
8271 GtkWidget *widget = GTK_WIDGET (window);
8272 gboolean has_focus = window->has_toplevel_focus && window->is_active;
8274 if (has_focus != window->has_focus)
8276 window->has_focus = has_focus;
8280 if (window->focus_widget &&
8281 window->focus_widget != widget &&
8282 !GTK_WIDGET_HAS_FOCUS (window->focus_widget))
8283 do_focus_change (window->focus_widget, TRUE);
8287 if (window->focus_widget &&
8288 window->focus_widget != widget &&
8289 GTK_WIDGET_HAS_FOCUS (window->focus_widget))
8290 do_focus_change (window->focus_widget, FALSE);
8296 * _gtk_window_set_is_active:
8297 * @window: a #GtkWindow
8298 * @is_active: %TRUE if the window is in the currently active toplevel
8300 * Internal function that sets whether the #GtkWindow is part
8301 * of the currently active toplevel window (taking into account inter-process
8305 _gtk_window_set_is_active (GtkWindow *window,
8308 g_return_if_fail (GTK_IS_WINDOW (window));
8310 is_active = is_active != FALSE;
8312 if (is_active != window->is_active)
8314 window->is_active = is_active;
8315 window_update_has_focus (window);
8317 g_object_notify (G_OBJECT (window), "is-active");
8322 * _gtk_windwo_set_is_toplevel:
8323 * @window: a #GtkWindow
8324 * @is_toplevel: %TRUE if the window is still a real toplevel (nominally a
8325 * parent of the root window); %FALSE if it is not (for example, for an
8326 * in-process, parented GtkPlug)
8328 * Internal function used by #GtkPlug when it gets parented/unparented by a
8329 * #GtkSocket. This keeps the @window's #GTK_TOPLEVEL flag in sync with the
8330 * global list of toplevel windows.
8333 _gtk_window_set_is_toplevel (GtkWindow *window,
8334 gboolean is_toplevel)
8336 if (GTK_WIDGET_TOPLEVEL (window))
8337 g_assert (g_slist_find (toplevel_list, window) != NULL);
8339 g_assert (g_slist_find (toplevel_list, window) == NULL);
8341 if (is_toplevel == GTK_WIDGET_TOPLEVEL (window))
8346 GTK_WIDGET_SET_FLAGS (window, GTK_TOPLEVEL);
8347 toplevel_list = g_slist_prepend (toplevel_list, window);
8351 GTK_WIDGET_UNSET_FLAGS (window, GTK_TOPLEVEL);
8352 toplevel_list = g_slist_remove (toplevel_list, window);
8357 * _gtk_window_set_has_toplevel_focus:
8358 * @window: a #GtkWindow
8359 * @has_toplevel_focus: %TRUE if the in
8361 * Internal function that sets whether the keyboard focus for the
8362 * toplevel window (taking into account inter-process embedding.)
8365 _gtk_window_set_has_toplevel_focus (GtkWindow *window,
8366 gboolean has_toplevel_focus)
8368 g_return_if_fail (GTK_IS_WINDOW (window));
8370 has_toplevel_focus = has_toplevel_focus != FALSE;
8372 if (has_toplevel_focus != window->has_toplevel_focus)
8374 window->has_toplevel_focus = has_toplevel_focus;
8375 window_update_has_focus (window);
8377 g_object_notify (G_OBJECT (window), "has-toplevel-focus");
8382 * gtk_window_set_auto_startup_notification:
8383 * @setting: %TRUE to automatically do startup notification
8385 * By default, after showing the first #GtkWindow, GTK+ calls
8386 * gdk_notify_startup_complete(). Call this function to disable
8387 * the automatic startup notification. You might do this if your
8388 * first window is a splash screen, and you want to delay notification
8389 * until after your real main window has been shown, for example.
8391 * In that example, you would disable startup notification
8392 * temporarily, show your splash screen, then re-enable it so that
8393 * showing the main window would automatically result in notification.
8398 gtk_window_set_auto_startup_notification (gboolean setting)
8400 disable_startup_notification = !setting;
8403 #if defined (G_OS_WIN32) && !defined (_WIN64)
8405 #undef gtk_window_set_icon_from_file
8408 gtk_window_set_icon_from_file (GtkWindow *window,
8409 const gchar *filename,
8412 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, err);
8415 if (utf8_filename == NULL)
8418 retval = gtk_window_set_icon_from_file_utf8 (window, utf8_filename, err);
8420 g_free (utf8_filename);
8425 #undef gtk_window_set_default_icon_from_file
8428 gtk_window_set_default_icon_from_file (const gchar *filename,
8431 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, err);
8434 if (utf8_filename == NULL)
8437 retval = gtk_window_set_default_icon_from_file_utf8 (utf8_filename, err);
8439 g_free (utf8_filename);
8446 #define __GTK_WINDOW_C__
8447 #include "gtkaliasdef.c"