* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*/
#include "config.h"
+
+#include "gtkwindow.h"
+
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
-#include "gdk/gdk.h"
-#include "gdk/gdkkeysyms.h"
-
-#include "gtkintl.h"
#include "gtkprivate.h"
-#include "gtkrc.h"
-#include "gtkwindow.h"
-#include "gtkwindow-decorate.h"
+#include "gtkwindowprivate.h"
+#include "gtkaccelgroupprivate.h"
#include "gtkbindings.h"
#include "gtkkeyhash.h"
#include "gtkmain.h"
#include "gtkplug.h"
#include "gtkbuildable.h"
#include "gtkwidgetprivate.h"
+#include "gtkcontainerprivate.h"
+#include "gtkintl.h"
+#include "gtkstylecontextprivate.h"
+#include "gtktypebuiltins.h"
+#include "a11y/gtkwindowaccessible.h"
+
+#include "deprecated/gtkstyle.h"
#ifdef GDK_WINDOWING_X11
#include "x11/gdkx.h"
* </refsect2>
*/
+#define AUTO_MNEMONICS_DELAY 300 /* ms */
+
typedef struct _GtkDeviceGrabInfo GtkDeviceGrabInfo;
-typedef struct _GtkWindowGroupPrivate GtkWindowGroupPrivate;
struct _GtkWindowPrivate
{
GtkMnemonicHash *mnemonic_hash;
+ GtkWidget *attach_widget;
GtkWidget *default_widget;
GtkWidget *focus_widget;
GtkWindow *transient_parent;
GtkWindowGeometryInfo *geometry_info;
GtkWindowGroup *group;
-
- GdkModifierType mnemonic_modifier;
GdkScreen *screen;
- GdkWindow *frame;
- GdkWindowTypeHint gdk_type_hint;
-
GtkApplication *application;
- gdouble opacity;
+ GdkModifierType mnemonic_modifier;
+ GdkWindowTypeHint gdk_type_hint;
GdkWindow *grip_window;
gchar *wmclass_name;
gchar *wm_role;
- guint frame_bottom;
- guint frame_left;
- guint frame_right;
- guint frame_top;
guint keys_changed_handler;
+ guint32 initial_timestamp;
+
guint16 configure_request_count;
+ guint auto_mnemonics_timeout_id;
+
/* The following flags are initially TRUE (before a window is mapped).
* They cause us to compute a configure request that involves
* default-only parameters. Once mapped, we set them to FALSE.
guint destroy_with_parent : 1;
guint focus_on_map : 1;
guint fullscreen_initially : 1;
- guint gravity : 5; /* GdkGravity */
guint has_focus : 1;
guint has_user_ref_count : 1;
- guint has_frame : 1;
guint has_toplevel_focus : 1;
+ guint hide_titlebar_when_maximized : 1;
guint iconify_initially : 1; /* gtk_window_iconify() called before realization */
guint is_active : 1;
guint maximize_initially : 1;
guint mnemonics_visible : 1;
guint mnemonics_visible_set : 1;
+ guint focus_visible : 1;
guint modal : 1;
- guint opacity_set : 1;
guint position : 3;
guint reset_type_hint : 1;
guint resizable : 1;
guint resize_grip_visible : 1; /* don't use, just for "resize-
* grip-visible" notification
*/
+ guint gravity : 5; /* GdkGravity */
};
PROP_DEFAULT_WIDTH,
PROP_DEFAULT_HEIGHT,
PROP_DESTROY_WITH_PARENT,
+ PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED,
PROP_ICON,
PROP_ICON_NAME,
PROP_SCREEN,
PROP_DELETABLE,
PROP_GRAVITY,
PROP_TRANSIENT_FOR,
- PROP_OPACITY,
+ PROP_ATTACHED_TO,
PROP_HAS_RESIZE_GRIP,
PROP_RESIZE_GRIP_VISIBLE,
PROP_APPLICATION,
/* Readonly properties */
PROP_IS_ACTIVE,
PROP_HAS_TOPLEVEL_FOCUS,
-
+
/* Writeonly properties */
PROP_STARTUP_ID,
-
+
PROP_MNEMONICS_VISIBLE,
+ PROP_FOCUS_VISIBLE,
LAST_ARG
};
GtkWindowLastGeometryInfo last;
};
-#define GTK_WINDOW_GROUP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_WINDOW_GROUP, GtkWindowGroupPrivate))
struct _GtkDeviceGrabInfo
{
struct _GtkWindowGroupPrivate
{
+ GSList *grabs;
GSList *device_grabs;
};
static void gtk_window_unrealize (GtkWidget *widget);
static void gtk_window_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static gint gtk_window_event (GtkWidget *widget,
- GdkEvent *event);
static gboolean gtk_window_map_event (GtkWidget *widget,
GdkEventAny *event);
-static gboolean gtk_window_frame_event (GtkWindow *window,
- GdkEvent *event);
static gint gtk_window_configure_event (GtkWidget *widget,
GdkEventConfigure *event);
static gint gtk_window_key_press_event (GtkWidget *widget,
GdkEventFocus *event);
static gint gtk_window_focus_out_event (GtkWidget *widget,
GdkEventFocus *event);
-static void gtk_window_style_set (GtkWidget *widget,
- GtkStyle *style);
-static gint gtk_window_client_event (GtkWidget *widget,
- GdkEventClient *event);
+static void gtk_window_style_updated (GtkWidget *widget);
static gboolean gtk_window_state_event (GtkWidget *widget,
GdkEventWindowState *event);
static void gtk_window_check_resize (GtkContainer *container);
static void gtk_window_free_key_hash (GtkWindow *window);
static void gtk_window_on_composited_changed (GdkScreen *screen,
GtkWindow *window);
+#ifdef GDK_WINDOWING_X11
+static void gtk_window_on_theme_variant_changed (GtkSettings *settings,
+ GParamSpec *pspec,
+ GtkWindow *window);
+#endif
+static void gtk_window_set_theme_variant (GtkWindow *window);
static GSList *toplevel_list = NULL;
static guint window_signals[LAST_SIGNAL] = { 0 };
const gchar *tagname,
gpointer user_data);
-
-static void gtk_window_get_preferred_width (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size);
-static void gtk_window_get_preferred_height (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size);
+static void ensure_state_flag_backdrop (GtkWidget *widget);
G_DEFINE_TYPE_WITH_CODE (GtkWindow, gtk_window, GTK_TYPE_BIN,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
widget_class->focus_in_event = gtk_window_focus_in_event;
widget_class->button_press_event = gtk_window_button_press_event;
widget_class->focus_out_event = gtk_window_focus_out_event;
- widget_class->client_event = gtk_window_client_event;
widget_class->focus = gtk_window_focus;
widget_class->move_focus = gtk_window_move_focus;
widget_class->draw = gtk_window_draw;
- widget_class->get_preferred_width = gtk_window_get_preferred_width;
- widget_class->get_preferred_height = gtk_window_get_preferred_height;
widget_class->window_state_event = gtk_window_state_event;
widget_class->direction_changed = gtk_window_direction_changed;
widget_class->state_changed = gtk_window_state_changed;
- widget_class->style_set = gtk_window_style_set;
+ widget_class->style_updated = gtk_window_style_updated;
container_class->check_resize = gtk_window_check_resize;
klass->set_focus = gtk_window_real_set_focus;
- klass->frame_event = gtk_window_frame_event;
klass->activate_default = gtk_window_real_activate_default;
klass->activate_focus = gtk_window_real_activate_focus;
FALSE,
GTK_PARAM_READWRITE));
+ /**
+ * GtkWindow:hide-titlebar-when-maximized:
+ *
+ * Whether the titlebar should be hidden during maximization.
+ *
+ * Since: 3.4
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED,
+ g_param_spec_boolean ("hide-titlebar-when-maximized",
+ P_("Hide the titlebar during maximization"),
+ P_("If this window's titlebar should be hidden when the window is maximized"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class,
PROP_ICON,
g_param_spec_object ("icon",
P_("Icon for this window"),
GDK_TYPE_PIXBUF,
GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWindow:mnemonics-visible:
+ *
+ * Whether mnemonics are currently visible in this window.
+ *
+ * This property is maintained by GTK+ based on the
+ * #GtkSettings:gtk-auto-mnemonics setting and user input,
+ * and should not be set by applications.
+ *
+ * Since: 2.20
+ */
g_object_class_install_property (gobject_class,
PROP_MNEMONICS_VISIBLE,
g_param_spec_boolean ("mnemonics-visible",
P_("Whether mnemonics are currently visible in this window"),
TRUE,
GTK_PARAM_READWRITE));
+
+ /**
+ * GtkWindow:focus-visible:
+ *
+ * Whether 'focus rectangles' are currently visible in this window.
+ *
+ * This property is maintained by GTK+ based on the
+ * #GtkSettings:gtk-visible-focus setting and user input
+ * and should not be set by applications.
+ *
+ * Since: 2.20
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_FOCUS_VISIBLE,
+ g_param_spec_boolean ("focus-visible",
+ P_("Focus Visible"),
+ P_("Whether focus rectangles are currently visible in this window"),
+ TRUE,
+ GTK_PARAM_READWRITE));
/**
* GtkWindow:icon-name:
GTK_PARAM_READWRITE));
/**
- * GtkWindow:has-resize-grip
+ * GtkWindow:has-resize-grip:
*
* Whether the window has a corner resize grip.
*
GTK_PARAM_READWRITE));
/**
- * GtkWindow: resize-grip-visible:
+ * GtkWindow:resize-grip-visible:
*
* Whether a corner resize grip is currently shown.
*
GTK_PARAM_READWRITE| G_PARAM_CONSTRUCT));
/**
- * GtkWindow:opacity:
+ * GtkWindow:attached-to:
*
- * The requested opacity of the window. See gtk_window_set_opacity() for
- * more details about window opacity.
+ * The widget to which this window is attached.
+ * See gtk_window_set_attached_to().
*
- * Since: 2.12
+ * Examples of places where specifying this relation is useful are
+ * for instance a #GtkMenu created by a #GtkComboBox, a completion
+ * popup window created by #GtkEntry or a typeahead search entry
+ * created by #GtkTreeView.
+ *
+ * Since: 3.4
*/
g_object_class_install_property (gobject_class,
- PROP_OPACITY,
- g_param_spec_double ("opacity",
- P_("Opacity for Window"),
- P_("The opacity of the window, from 0 to 1"),
- 0.0,
- 1.0,
- 1.0,
- GTK_PARAM_READWRITE));
+ PROP_ATTACHED_TO,
+ g_param_spec_object ("attached-to",
+ P_("Attached to Widget"),
+ P_("The widget where the window is attached"),
+ GTK_TYPE_WIDGET,
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/* Style properties.
*/
0, G_MAXINT, 16, GTK_PARAM_READWRITE));
- /* Signals
- */
/**
* GtkWindow:application:
*
* The #GtkApplication associated with the window.
*
- * The application will be kept alive for at least as long as the
- * window is open.
+ * The application will be kept alive for at least as long as it
+ * has any windows associated with it (see g_application_hold()
+ * for a way to keep it alive without windows).
+ *
+ * Normally, the connection between the application and the window
+ * will remain until the window is destroyed, but you can explicitly
+ * remove it by setting the ::application property to %NULL.
*
* Since: 3.0
*/
_gtk_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GTK_TYPE_WIDGET);
-
- window_signals[FRAME_EVENT] =
- g_signal_new (I_("frame-event"),
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(GtkWindowClass, frame_event),
- _gtk_boolean_handled_accumulator, NULL,
- _gtk_marshal_BOOLEAN__BOXED,
- G_TYPE_BOOLEAN, 1,
- GDK_TYPE_EVENT);
/**
* GtkWindow::activate-focus:
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
+
+ gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_WINDOW_ACCESSIBLE);
}
static void
gtk_window_init (GtkWindow *window)
{
+ GtkStyleContext *context;
GtkWindowPrivate *priv;
window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
priv->need_default_size = TRUE;
priv->need_default_position = TRUE;
priv->modal = FALSE;
- priv->frame = NULL;
- priv->has_frame = FALSE;
- priv->frame_left = 0;
- priv->frame_right = 0;
- priv->frame_top = 0;
- priv->frame_bottom = 0;
priv->gdk_type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
priv->gravity = GDK_GRAVITY_NORTH_WEST;
priv->decorated = TRUE;
priv->focus_on_map = TRUE;
priv->deletable = TRUE;
priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
- priv->opacity = 1.0;
priv->startup_id = NULL;
+ priv->initial_timestamp = GDK_CURRENT_TIME;
priv->has_resize_grip = TRUE;
priv->mnemonics_visible = TRUE;
+ priv->focus_visible = TRUE;
g_object_ref_sink (window);
priv->has_user_ref_count = TRUE;
toplevel_list = g_slist_prepend (toplevel_list, window);
- gtk_decorated_window_init (window);
+ if (priv->screen)
+ g_signal_connect (priv->screen, "composited-changed",
+ G_CALLBACK (gtk_window_on_composited_changed), window);
+
+#ifdef GDK_WINDOWING_X11
+ g_signal_connect (gtk_settings_get_for_screen (priv->screen),
+ "notify::gtk-application-prefer-dark-theme",
+ G_CALLBACK (gtk_window_on_theme_variant_changed), window);
+#endif
- g_signal_connect (priv->screen, "composited-changed",
- G_CALLBACK (gtk_window_on_composited_changed), window);
+ context = gtk_widget_get_style_context (GTK_WIDGET (window));
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_BACKGROUND);
}
static void
case PROP_DESTROY_WITH_PARENT:
gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
break;
+ case PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED:
+ gtk_window_set_hide_titlebar_when_maximized (window, g_value_get_boolean (value));
+ break;
case PROP_ICON:
gtk_window_set_icon (window,
g_value_get_object (value));
case PROP_TRANSIENT_FOR:
gtk_window_set_transient_for (window, g_value_get_object (value));
break;
- case PROP_OPACITY:
- gtk_window_set_opacity (window, g_value_get_double (value));
+ case PROP_ATTACHED_TO:
+ gtk_window_set_attached_to (window, g_value_get_object (value));
break;
case PROP_HAS_RESIZE_GRIP:
gtk_window_set_has_resize_grip (window, g_value_get_boolean (value));
case PROP_MNEMONICS_VISIBLE:
gtk_window_set_mnemonics_visible (window, g_value_get_boolean (value));
break;
+ case PROP_FOCUS_VISIBLE:
+ gtk_window_set_focus_visible (window, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_DESTROY_WITH_PARENT:
g_value_set_boolean (value, priv->destroy_with_parent);
break;
+ case PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED:
+ g_value_set_boolean (value, priv->hide_titlebar_when_maximized);
+ break;
case PROP_ICON:
g_value_set_object (value, gtk_window_get_icon (window));
break;
case PROP_TRANSIENT_FOR:
g_value_set_object (value, gtk_window_get_transient_for (window));
break;
- case PROP_OPACITY:
- g_value_set_double (value, gtk_window_get_opacity (window));
+ case PROP_ATTACHED_TO:
+ g_value_set_object (value, gtk_window_get_attached_to (window));
break;
case PROP_HAS_RESIZE_GRIP:
g_value_set_boolean (value, priv->has_resize_grip);
case PROP_MNEMONICS_VISIBLE:
g_value_set_boolean (value, priv->mnemonics_visible);
break;
+ case PROP_FOCUS_VISIBLE:
+ g_value_set_boolean (value, priv->focus_visible);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
{
gdk_window_set_title (gtk_widget_get_window (widget),
priv->title);
-
- gtk_decorated_window_set_title (window, title);
}
g_object_notify (G_OBJECT (window), "title");
* been set explicitely. The returned string is owned by the widget
* and must not be modified or freed.
**/
-G_CONST_RETURN gchar *
+const gchar *
gtk_window_get_title (GtkWindow *window)
{
g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
gdk_window = gtk_widget_get_window (widget);
#ifdef GDK_WINDOWING_X11
- if (timestamp != GDK_CURRENT_TIME)
+ if (timestamp != GDK_CURRENT_TIME && GDK_IS_X11_WINDOW(gdk_window))
gdk_x11_window_set_user_time (gdk_window, timestamp);
#endif
* returned is owned by the widget and must not be modified
* or freed.
**/
-G_CONST_RETURN gchar *
+const gchar *
gtk_window_get_role (GtkWindow *window)
{
g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
* unsets the default widget for a #GtkWindow about. When setting
* (rather than unsetting) the default widget it's generally easier to
* call gtk_widget_grab_focus() on the widget. Before making a widget
- * the default widget, you must set the #GTK_CAN_DEFAULT flag on the
- * widget you'd like to make the default using GTK_WIDGET_SET_FLAGS().
+ * the default widget, you must call gtk_widget_set_can_default() on the
+ * widget you'd like to make the default.
**/
void
gtk_window_set_default (GtkWindow *window,
* gtk_window_mnemonic_activate:
* @window: a #GtkWindow
* @keyval: the mnemonic
- * @modifier: the modifiers
- * @returns: %TRUE if the activation is done.
- *
+ * @modifier: the modifiers
+ *
* Activates the targets associated with the mnemonic.
+ *
+ * Returns: %TRUE if the activation is done.
*/
gboolean
gtk_window_mnemonic_activate (GtkWindow *window,
return list;
}
-void
-gtk_window_add_embedded_xid (GtkWindow *window, GdkNativeWindow xid)
-{
- GList *embedded_windows;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- embedded_windows = g_object_get_qdata (G_OBJECT (window), quark_gtk_embedded);
- if (embedded_windows)
- g_object_steal_qdata (G_OBJECT (window), quark_gtk_embedded);
- embedded_windows = g_list_prepend (embedded_windows,
- GUINT_TO_POINTER (xid));
-
- g_object_set_qdata_full (G_OBJECT (window), quark_gtk_embedded,
- embedded_windows,
- embedded_windows ?
- (GDestroyNotify) g_list_free : NULL);
-}
-
-void
-gtk_window_remove_embedded_xid (GtkWindow *window, GdkNativeWindow xid)
+static void
+remove_attach_widget (GtkWindow *window)
{
- GList *embedded_windows;
- GList *node;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- embedded_windows = g_object_get_qdata (G_OBJECT (window), quark_gtk_embedded);
- if (embedded_windows)
- g_object_steal_qdata (G_OBJECT (window), quark_gtk_embedded);
+ GtkWindowPrivate *priv = window->priv;
- node = g_list_find (embedded_windows, GUINT_TO_POINTER (xid));
- if (node)
+ if (priv->attach_widget)
{
- embedded_windows = g_list_remove_link (embedded_windows, node);
- g_list_free_1 (node);
+ _gtk_widget_remove_attached_window (priv->attach_widget, window);
+
+ g_object_unref (priv->attach_widget);
+ priv->attach_widget = NULL;
}
-
- g_object_set_qdata_full (G_OBJECT (window), quark_gtk_embedded,
- embedded_windows,
- embedded_windows ?
- (GDestroyNotify) g_list_free : NULL);
}
static void
gtk_window_set_focus (window, NULL);
gtk_window_set_default (window, NULL);
+ remove_attach_widget (GTK_WINDOW (object));
+
G_OBJECT_CLASS (gtk_window_parent_class)->dispose (object);
}
return window->priv->transient_parent;
}
+/**
+ * gtk_window_set_attached_to:
+ * @window: a #GtkWindow
+ * @attach_widget: (allow-none): a #GtkWidget, or %NULL
+ *
+ * Marks @window as attached to @attach_widget. This creates a logical binding
+ * between the window and the widget it belongs to, which is used by GTK+ to
+ * propagate information such as styling or accessibility to @window as if it
+ * was a children of @attach_widget.
+ *
+ * Examples of places where specifying this relation is useful are for instance
+ * a #GtkMenu created by a #GtkComboBox, a completion popup window
+ * created by #GtkEntry or a typeahead search entry created by #GtkTreeView.
+ *
+ * Note that this function should not be confused with
+ * gtk_window_set_transient_for(), which specifies a window manager relation
+ * between two toplevels instead.
+ *
+ * Passing %NULL for @attach_widget detaches the window.
+ *
+ * Since: 3.4
+ **/
+void
+gtk_window_set_attached_to (GtkWindow *window,
+ GtkWidget *attach_widget)
+{
+ GtkStyleContext *context;
+ GtkWindowPrivate *priv;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+ g_return_if_fail (GTK_WIDGET (window) != attach_widget);
+
+ priv = window->priv;
+
+ if (priv->attach_widget == attach_widget)
+ return;
+
+ remove_attach_widget (window);
+
+ priv->attach_widget = attach_widget;
+
+ if (priv->attach_widget)
+ {
+ _gtk_widget_add_attached_window (priv->attach_widget, window);
+
+ g_object_ref (priv->attach_widget);
+ }
+
+ /* Update the style, as the widget path might change. */
+ context = gtk_widget_get_style_context (GTK_WIDGET (window));
+ if (priv->attach_widget)
+ gtk_style_context_set_parent (context, gtk_widget_get_style_context (priv->attach_widget));
+ else
+ gtk_style_context_set_parent (context, NULL);
+}
+
+/**
+ * gtk_window_get_attached_to:
+ * @window: a #GtkWindow
+ *
+ * Fetches the attach widget for this window. See
+ * gtk_window_set_attached_to().
+ *
+ * Return value: (transfer none): the widget where the window is attached,
+ * or %NULL if the window is not attached to any widget.
+ *
+ * Since: 3.4
+ **/
+GtkWidget *
+gtk_window_get_attached_to (GtkWindow *window)
+{
+ g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+
+ return window->priv->attach_widget;
+}
+
/**
* gtk_window_set_opacity:
* @window: a #GtkWindow
* shown causes it to flicker once on Windows.
*
* Since: 2.12
+ * Deprecated: 3.8: Use gtk_widget_set_opacity instead.
**/
void
gtk_window_set_opacity (GtkWindow *window,
gdouble opacity)
{
- GtkWindowPrivate *priv;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- priv = window->priv;
-
- if (opacity < 0.0)
- opacity = 0.0;
- else if (opacity > 1.0)
- opacity = 1.0;
-
- priv->opacity_set = TRUE;
- priv->opacity = opacity;
-
- if (gtk_widget_get_realized (GTK_WIDGET (window)))
- gdk_window_set_opacity (gtk_widget_get_window (GTK_WIDGET (window)),
- priv->opacity);
+ gtk_widget_set_opacity (GTK_WIDGET (window), opacity);
}
/**
* Return value: the requested opacity for this window.
*
* Since: 2.12
+ * Deprecated: 3.8: Use gtk_widget_get_opacity instead.
**/
gdouble
gtk_window_get_opacity (GtkWindow *window)
{
g_return_val_if_fail (GTK_IS_WINDOW (window), 0.0);
- return window->priv->opacity;
+ return gtk_widget_get_opacity (GTK_WIDGET (window));
}
/**
*
* Gets the #GtkApplication associated with the window (if any).
*
- * Return value: a #GtkApplication, or %NULL
+ * Return value: (transfer none): a #GtkApplication, or %NULL
*
* Since: 3.0
**/
/**
* gtk_window_set_application:
* @window: a #GtkWindow
- * @application: a #GtkApplication, or %NULL
+ * @application: (allow-none): a #GtkApplication, or %NULL
*
* Sets or unsets the #GtkApplication associated with the window.
*
gtk_application_add_window (priv->application, window);
}
+ /* don't use a normal cast: application may be NULL */
+ gtk_widget_insert_action_group (GTK_WIDGET (window), "app", (GActionGroup *) application);
+
g_object_notify (G_OBJECT (window), "application");
}
}
priv = window->priv;
if (hint < GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU)
- priv->gdk_type_hint = hint;
+ priv->type_hint = hint;
else
- priv->gdk_type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
+ priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
priv->reset_type_hint = TRUE;
- priv->type_hint = hint;
+ priv->gdk_type_hint = hint;
}
/**
{
g_return_val_if_fail (GTK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
- return window->priv->type_hint;
+ return window->priv->gdk_type_hint;
}
/**
return window->priv->destroy_with_parent;
}
+/**
+ * gtk_window_set_hide_titlebar_when_maximized:
+ * @window: a #GtkWindow
+ * @setting: whether to hide the titlebar when @window is maximized
+ *
+ * If @setting is %TRUE, then @window will request that it's titlebar
+ * should be hidden when maximized.
+ * This is useful for windows that don't convey any information other
+ * than the application name in the titlebar, to put the available
+ * screen space to better use. If the underlying window system does not
+ * support the request, the setting will not have any effect.
+ *
+ * Since: 3.4
+ **/
+void
+gtk_window_set_hide_titlebar_when_maximized (GtkWindow *window,
+ gboolean setting)
+{
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+#ifdef GDK_WINDOWING_X11
+ {
+ GdkWindow *gdk_window;
+
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+ if (GDK_IS_X11_WINDOW (gdk_window))
+ gdk_x11_window_set_hide_titlebar_when_maximized (gdk_window, setting);
+ }
+#endif
+
+ window->priv->hide_titlebar_when_maximized = setting;
+ g_object_notify (G_OBJECT (window), "hide-titlebar-when-maximized");
+}
+
+/**
+ * gtk_window_get_hide_titlebar_when_maximized:
+ * @window: a #GtkWindow
+ *
+ * Returns whether the window has requested to have its titlebar hidden
+ * when maximized. See gtk_window_set_hide_titlebar_when_maximized ().
+ *
+ * Return value: %TRUE if the window has requested to have its titlebar
+ * hidden when maximized
+ *
+ * Since: 3.4
+ **/
+gboolean
+gtk_window_get_hide_titlebar_when_maximized (GtkWindow *window)
+{
+ g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+ return window->priv->hide_titlebar_when_maximized;
+}
+
static GtkWindowGeometryInfo*
gtk_window_get_geometry_info (GtkWindow *window,
gboolean create)
* using this function, GTK+ will do its best to convince the window
* manager not to decorate the window. Depending on the system, this
* function may not have any effect when called on a window that is
- * already visible, so you should call it before calling gtk_window_show().
+ * already visible, so you should call it before calling gtk_widget_show().
*
* On Windows, this function always works, since there's no window manager
* policy involved.
* using this function, GTK+ will do its best to convince the window
* manager not to show a close button. Depending on the system, this
* function may not have any effect when called on a window that is
- * already visible, so you should call it before calling gtk_window_show().
+ * already visible, so you should call it before calling gtk_widget_show().
*
* On Windows, this function always works, since there's no window manager
* policy involved.
{
GtkIconTheme *icon_theme;
- g_list_foreach (icon_list, (GFunc) g_object_unref, NULL);
- g_list_free (icon_list);
+ g_list_free_full (icon_list, g_object_unref);
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)));
g_signal_connect (icon_theme, "changed",
/**
* gtk_window_set_icon_list:
* @window: a #GtkWindow
- * @list: (element-type GdkPixbuf) (transfer container): list of #GdkPixbuf
+ * @list: (element-type GdkPixbuf): list of #GdkPixbuf
*
* Sets up the icon representing a #GtkWindow. The icon is used when
* the window is minimized (also known as iconified). Some window
g_list_foreach (list,
(GFunc) g_object_ref, NULL);
- g_list_foreach (info->icon_list,
- (GFunc) g_object_unref, NULL);
-
- g_list_free (info->icon_list);
+ g_list_free_full (info->icon_list, g_object_unref);
info->icon_list = g_list_copy (list);
info->icon_name = g_strdup (name);
g_free (tmp);
- g_list_foreach (info->icon_list, (GFunc) g_object_unref, NULL);
- g_list_free (info->icon_list);
+ g_list_free_full (info->icon_list, g_object_unref);
info->icon_list = NULL;
update_themed_icon (NULL, window);
/**
* gtk_window_set_icon_from_file:
* @window: a #GtkWindow
- * @filename: location of icon file
+ * @filename: (type filename): location of icon file
* @err: (allow-none): location to store error, or %NULL.
*
* Sets the icon for @window.
g_list_foreach (list,
(GFunc) g_object_ref, NULL);
- g_list_foreach (default_icon_list,
- (GFunc) g_object_unref, NULL);
-
- g_list_free (default_icon_list);
+ g_list_free_full (default_icon_list, g_object_unref);
default_icon_list = g_list_copy (list);
g_free (default_icon_name);
default_icon_name = g_strdup (name);
- g_list_foreach (default_icon_list,
- (GFunc) g_object_unref, NULL);
-
- g_list_free (default_icon_list);
+ g_list_free_full (default_icon_list, g_object_unref);
default_icon_list = NULL;
/* Update all toplevels */
/**
* gtk_window_set_default_icon_from_file:
- * @filename: location of icon file
+ * @filename: (type filename): location of icon file
* @err: (allow-none): location to store error, or %NULL.
*
* Sets an icon to be used as fallback for windows that haven't
* gdk_screen_height () - window_height)</literal> (note that this
* example does not take multi-head scenarios into account).
*
- * The Extended Window Manager Hints specification at <ulink
+ * The Extended Window Manager Hints specification at <ulink
* url="http://www.freedesktop.org/Standards/wm-spec">
- * http://www.freedesktop.org/Standards/wm-spec</ulink> has a
+ * http://www.freedesktop.org/Standards/wm-spec</ulink> has a
* nice table of gravities in the "implementation notes" section.
*
* The gtk_window_get_position() documentation may also be relevant.
gint x,
gint y)
{
- GtkWindowPrivate *priv;
GtkWindowGeometryInfo *info;
GtkWidget *widget;
-
+
g_return_if_fail (GTK_IS_WINDOW (window));
- priv = window->priv;
widget = GTK_WIDGET (window);
info = gtk_window_get_geometry_info (window, TRUE);
-
+
if (gtk_widget_get_mapped (widget))
{
GtkAllocation allocation;
gtk_window_constrain_position (window,
allocation.width, allocation.height,
&x, &y);
-
+
/* Note that this request doesn't go through our standard request
* framework, e.g. doesn't increment configure_request_count,
* doesn't set info->last, etc.; that's because
* the same as the position being changed by the window
* manager.
*/
-
- /* FIXME are we handling gravity properly for framed windows? */
- if (priv->frame)
- gdk_window_move (priv->frame,
- x - priv->frame_left,
- y - priv->frame_top);
- else
- gdk_window_move (gtk_widget_get_window (GTK_WIDGET (window)),
- x, y);
+ gdk_window_move (gtk_widget_get_window (GTK_WIDGET (window)), x, y);
}
else
{
/**
* gtk_window_get_position:
* @window: a #GtkWindow
- * @root_x: (out): return location for X coordinate of gravity-determined reference point
- * @root_y: (out): return location for Y coordinate of gravity-determined reference point
+ * @root_x: (out) (allow-none): return location for X coordinate of
+ * gravity-determined reference point, or %NULL
+ * @root_y: (out) (allow-none): return location for Y coordinate of
+ * gravity-determined reference point, or %NULL
*
* This function returns the position you need to pass to
- * gtk_window_move() to keep @window in its current position. This
- * means that the meaning of the returned value varies with window
- * gravity. See gtk_window_move() for more details.
- *
+ * gtk_window_move() to keep @window in its current position.
+ * This means that the meaning of the returned value varies with
+ * window gravity. See gtk_window_move() for more details.
+ *
* If you haven't changed the window gravity, its gravity will be
* #GDK_GRAVITY_NORTH_WEST. This means that gtk_window_get_position()
* gets the position of the top-left corner of the window manager
if (gtk_widget_get_mapped (widget))
{
- if (priv->frame)
- gdk_window_get_frame_extents (priv->frame, &frame_extents);
- else
- gdk_window_get_frame_extents (gdk_window, &frame_extents);
+ gdk_window_get_frame_extents (gdk_window, &frame_extents);
x = frame_extents.x;
y = frame_extents.y;
gtk_window_get_size (window, &w, &h);
{
/* We just say the frame has 0 size on all sides.
* Not sure what else to do.
- */
+ */
gtk_window_compute_configure_request (window,
&frame_extents,
NULL, NULL);
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
+ gtk_window_release_application (window);
+
toplevel_list = g_slist_remove (toplevel_list, window);
if (priv->transient_parent)
gtk_window_set_transient_for (window, NULL);
+ remove_attach_widget (GTK_WINDOW (widget));
+
/* frees the icons */
gtk_window_set_icon_list (window, NULL);
-
+
if (priv->has_user_ref_count)
{
priv->has_user_ref_count = FALSE;
g_free (priv->startup_id);
+ if (priv->auto_mnemonics_timeout_id)
+ {
+ g_source_remove (priv->auto_mnemonics_timeout_id);
+ priv->auto_mnemonics_timeout_id = 0;
+ }
+
+#ifdef GDK_WINDOWING_X11
+ g_signal_handlers_disconnect_by_func (gtk_settings_get_default (),
+ gtk_window_on_theme_variant_changed,
+ window);
+#endif
+
G_OBJECT_CLASS (gtk_window_parent_class)->finalize (object);
}
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
GtkContainer *container = GTK_CONTAINER (window);
+ GtkBitmask *empty;
gboolean need_resize;
+ gboolean is_plug;
+
+ if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+ {
+ GTK_WIDGET_CLASS (gtk_window_parent_class)->show (widget);
+ return;
+ }
_gtk_widget_set_visible_flag (widget, TRUE);
- need_resize = _gtk_container_get_need_resize (container) || !gtk_widget_get_realized (widget);
- _gtk_container_set_need_resize (container, FALSE);
+ need_resize = _gtk_widget_get_alloc_needed (widget) || !gtk_widget_get_realized (widget);
+
+ empty = _gtk_bitmask_new ();
+ _gtk_style_context_validate (gtk_widget_get_style_context (widget),
+ g_get_monotonic_time (),
+ 0,
+ empty);
+ _gtk_bitmask_free (empty);
if (need_resize)
{
was_realized = TRUE;
}
- /* Must be done after the windows are realized,
- * so that the decorations can be read
- */
- gtk_decorated_window_calculate_frame_size (window);
-
/* We only send configure request if we didn't just finish
* creating the window; if we just created the window
* then we created it with widget->allocation anyhow.
/* Try to make sure that we have some focused widget
*/
- if (!priv->focus_widget && !GTK_IS_PLUG (window))
+#ifdef GDK_WINDOWING_X11
+ is_plug = GDK_IS_X11_WINDOW (gtk_widget_get_window (widget)) &&
+ GTK_IS_PLUG (window);
+#else
+ is_plug = FALSE;
+#endif
+ if (!priv->focus_widget && !is_plug)
gtk_window_move_focus (widget, GTK_DIR_TAB_FORWARD);
if (priv->modal)
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
+ if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+ {
+ GTK_WIDGET_CLASS (gtk_window_parent_class)->hide (widget);
+ return;
+ }
+
_gtk_widget_set_visible_flag (widget, FALSE);
gtk_widget_unmap (widget);
GtkWidget *child;
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
- GdkWindow *toplevel;
GdkWindow *gdk_window;
gboolean auto_mnemonics;
+ GtkPolicyType visible_focus;
- gdk_window = gtk_widget_get_window (widget);
+ if (!gtk_widget_is_toplevel (widget))
+ {
+ GTK_WIDGET_CLASS (gtk_window_parent_class)->map (widget);
+ return;
+ }
gtk_widget_set_mapped (widget, TRUE);
!gtk_widget_get_mapped (child))
gtk_widget_map (child);
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gdk_window;
+ gdk_window = gtk_widget_get_window (widget);
if (priv->maximize_initially)
- gdk_window_maximize (toplevel);
+ gdk_window_maximize (gdk_window);
else
- gdk_window_unmaximize (toplevel);
-
+ gdk_window_unmaximize (gdk_window);
+
if (priv->stick_initially)
- gdk_window_stick (toplevel);
+ gdk_window_stick (gdk_window);
else
- gdk_window_unstick (toplevel);
-
+ gdk_window_unstick (gdk_window);
+
if (priv->iconify_initially)
- gdk_window_iconify (toplevel);
+ gdk_window_iconify (gdk_window);
else
- gdk_window_deiconify (toplevel);
+ gdk_window_deiconify (gdk_window);
if (priv->fullscreen_initially)
- gdk_window_fullscreen (toplevel);
+ gdk_window_fullscreen (gdk_window);
else
- gdk_window_unfullscreen (toplevel);
-
- gdk_window_set_keep_above (toplevel, priv->above_initially);
+ gdk_window_unfullscreen (gdk_window);
- gdk_window_set_keep_below (toplevel, priv->below_initially);
+ gdk_window_set_keep_above (gdk_window, priv->above_initially);
+
+ gdk_window_set_keep_below (gdk_window, priv->below_initially);
+
+ if (priv->type == GTK_WINDOW_TOPLEVEL)
+ {
+ gtk_window_set_theme_variant (window);
+ gtk_window_set_hide_titlebar_when_maximized (window,
+ priv->hide_titlebar_when_maximized);
+ }
/* No longer use the default settings */
priv->need_default_size = FALSE;
priv->need_default_position = FALSE;
-
+
if (priv->reset_type_hint)
{
/* We should only reset the type hint when the application
* Some applications use X directly to change the properties;
* in that case, we shouldn't overwrite what they did.
*/
- gdk_window_set_type_hint (gdk_window, priv->type_hint);
+ gdk_window_set_type_hint (gdk_window, priv->gdk_type_hint);
priv->reset_type_hint = FALSE;
}
gdk_window_show (gdk_window);
- if (priv->frame)
- gdk_window_show (priv->frame);
-
if (priv->grip_window)
gdk_window_show (priv->grip_window);
if (priv->startup_id != NULL)
{
/* Make sure we have a "real" id */
- if (!startup_id_is_fake (priv->startup_id))
+ if (!startup_id_is_fake (priv->startup_id))
gdk_notify_startup_complete_with_id (priv->startup_id);
g_free (priv->startup_id);
/* if auto-mnemonics is enabled and mnemonics visible is not already set
* (as in the case of popup menus), then hide mnemonics initially
*/
- g_object_get (gtk_widget_get_settings (widget), "gtk-auto-mnemonics",
- &auto_mnemonics, NULL);
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-auto-mnemonics", &auto_mnemonics,
+ "gtk-visible-focus", &visible_focus,
+ NULL);
+
if (auto_mnemonics && !priv->mnemonics_visible_set)
gtk_window_set_mnemonics_visible (window, FALSE);
+
+ /* inherit from transient parent, so that a dialog that is
+ * opened via keynav shows focus initially
+ */
+ if (priv->transient_parent)
+ gtk_window_set_focus_visible (window, gtk_window_get_focus_visible (priv->transient_parent));
+ else
+ gtk_window_set_focus_visible (window, visible_focus == GTK_POLICY_ALWAYS);
}
static gboolean
{
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
+ GtkWidget *child;
GtkWindowGeometryInfo *info;
GdkWindow *gdk_window;
GdkWindowState state;
+ if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+ {
+ GTK_WIDGET_CLASS (gtk_window_parent_class)->unmap (widget);
+ return;
+ }
+
gdk_window = gtk_widget_get_window (widget);
gtk_widget_set_mapped (widget, FALSE);
- if (priv->frame)
- gdk_window_withdraw (priv->frame);
- else
- gdk_window_withdraw (gdk_window);
+ gdk_window_withdraw (gdk_window);
priv->configure_request_count = 0;
priv->configure_notify_received = FALSE;
priv->stick_initially = (state & GDK_WINDOW_STATE_STICKY) != 0;
priv->above_initially = (state & GDK_WINDOW_STATE_ABOVE) != 0;
priv->below_initially = (state & GDK_WINDOW_STATE_BELOW) != 0;
-}
+
+ child = gtk_bin_get_child (&(window->bin));
+ if (child)
+ gtk_widget_unmap (child);
+}
+
+/* (Note: Replace "size" with "width" or "height". Also, the request
+ * mode is honoured.)
+ * For selecting the default window size, the following conditions
+ * should hold (in order of importance):
+ * - the size is not below the minimum size
+ * Windows cannot be resized below their minimum size, so we must
+ * ensure we don't do that either.
+ * - the size is not above the natural size
+ * It seems weird to allocate more than this in an initial guess.
+ * - the size does not exceed that of a maximized window
+ * We want to see the whole window after all.
+ * (Note that this may not be possible to achieve due to imperfect
+ * information from the windowing system.)
+ */
+
+/* We use these for now to not make windows too big by accident. Note
+ * that we still clamp these numbers by screen size. Also note that
+ * minimum size still overrides this. So keep your windows small! :)
+ */
+#define MAX_DEFAULT_WINDOW_WIDTH 640
+#define MAX_DEFAULT_WINDOW_HEIGHT 480
static void
-gtk_window_realize (GtkWidget *widget)
+gtk_window_guess_default_size (GtkWindow *window,
+ gint *width,
+ gint *height)
{
- GtkAllocation allocation;
+ GtkWidget *widget = GTK_WIDGET (window);
+ GdkScreen *screen;
+ int minimum, natural;
+
+ screen = gtk_widget_get_screen (widget);
+
+ *width = gdk_screen_get_width (screen);
+ *height = gdk_screen_get_height (screen);
+
+ if (*width >= *height)
+ {
+ /* landscape */
+ *width = MIN (*width, MAX_DEFAULT_WINDOW_WIDTH);
+ *height = MIN (*height, MAX_DEFAULT_WINDOW_HEIGHT);
+ }
+ else
+ {
+ /* portrait */
+ *width = MIN (*width, MAX_DEFAULT_WINDOW_HEIGHT);
+ *height = MIN (*height, MAX_DEFAULT_WINDOW_WIDTH);
+ }
+
+ if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
+ {
+ gtk_widget_get_preferred_height (widget, &minimum, &natural);
+ *height = MAX (minimum, MIN (*height, natural));
+
+ gtk_widget_get_preferred_width_for_height (widget, *height, &minimum, &natural);
+ *width = MAX (minimum, MIN (*width, natural));
+ }
+ else /* GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH or CONSTANT_SIZE */
+ {
+ gtk_widget_get_preferred_width (widget, &minimum, &natural);
+ *width = MAX (minimum, MIN (*width, natural));
+
+ gtk_widget_get_preferred_height_for_width (widget, *width, &minimum, &natural);
+ *height = MAX (minimum, MIN (*height, natural));
+ }
+}
+
+static void
+gtk_window_realize (GtkWidget *widget)
+{
+ GtkAllocation allocation;
GtkWindow *window;
- GtkStyle *style;
GdkWindow *parent_window;
GdkWindow *gdk_window;
GdkWindowAttr attributes;
gint attributes_mask;
GtkWindowPrivate *priv;
+ GtkStyleContext *context;
window = GTK_WINDOW (widget);
priv = window->priv;
gtk_widget_get_allocation (widget, &allocation);
+ if (gtk_widget_get_parent_window (widget))
+ {
+ gtk_container_set_resize_mode (GTK_CONTAINER (widget), GTK_RESIZE_PARENT);
+
+ gtk_widget_set_realized (widget, TRUE);
+
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.window_type = GDK_WINDOW_CHILD;
+
+ attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK;
+
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.wclass = GDK_INPUT_OUTPUT;
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+ gdk_window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gtk_widget_set_window (widget, gdk_window);
+ gtk_widget_register_window (widget, gdk_window);
+
+ gtk_style_context_set_background (gtk_widget_get_style_context (widget), gdk_window);
+
+ return;
+ }
+
+ gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
+
/* ensure widget tree is properly size allocated */
if (allocation.x == -1 &&
allocation.y == -1 &&
allocation.width == 1 &&
allocation.height == 1)
{
- GtkRequisition requisition;
allocation.x = 0;
allocation.y = 0;
- allocation.width = 200;
- allocation.height = 200;
- gtk_widget_get_preferred_size (widget, &requisition, NULL);
- if (requisition.width || requisition.height)
+ gtk_window_guess_default_size (window, &allocation.width, &allocation.height);
+ if (allocation.width == 0 || allocation.height == 0)
{
/* non-empty window */
- allocation.width = requisition.width;
- allocation.height = requisition.height;
+ allocation.width = 200;
+ allocation.height = 200;
}
gtk_widget_size_allocate (widget, &allocation);
g_warning (G_STRLOC": Unknown window type %d!", priv->type);
break;
}
-
+
attributes.title = priv->title;
attributes.wmclass_name = priv->wmclass_name;
attributes.wmclass_class = priv->wmclass_class;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
- if (priv->has_frame)
- {
- gtk_widget_get_allocation (widget, &allocation);
- attributes.width = allocation.width + priv->frame_left + priv->frame_right;
- attributes.height = allocation.height + priv->frame_top + priv->frame_bottom;
- attributes.event_mask = (GDK_EXPOSURE_MASK |
- GDK_KEY_PRESS_MASK |
- GDK_ENTER_NOTIFY_MASK |
- GDK_LEAVE_NOTIFY_MASK |
- GDK_FOCUS_CHANGE_MASK |
- GDK_STRUCTURE_MASK |
- GDK_BUTTON_MOTION_MASK |
- GDK_POINTER_MOTION_HINT_MASK |
- GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK);
-
- attributes_mask = GDK_WA_VISUAL;
-
- priv->frame = gdk_window_new (gtk_widget_get_root_window (widget),
- &attributes, attributes_mask);
-
- if (priv->opacity_set)
- gdk_window_set_opacity (priv->frame, priv->opacity);
-
- gdk_window_set_user_data (priv->frame, widget);
-
- attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = priv->frame_left;
- attributes.y = priv->frame_top;
-
- attributes_mask = GDK_WA_X | GDK_WA_Y;
-
- parent_window = priv->frame;
-
- g_signal_connect (window,
- "event",
- G_CALLBACK (gtk_window_event),
- NULL);
- }
- else
- {
- attributes_mask = 0;
- parent_window = gtk_widget_get_root_window (widget);
- }
+ attributes_mask = 0;
+ parent_window = gtk_widget_get_root_window (widget);
gtk_widget_get_allocation (widget, &allocation);
attributes.width = allocation.width;
gdk_window = gdk_window_new (parent_window, &attributes, attributes_mask);
gtk_widget_set_window (widget, gdk_window);
- if (!priv->has_frame && priv->opacity_set)
- gdk_window_set_opacity (gdk_window, priv->opacity);
-
- gdk_window_enable_synchronized_configure (gdk_window);
+ gtk_widget_register_window (widget, gdk_window);
- gdk_window_set_user_data (gdk_window, window);
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_set_background (context, gdk_window);
- gtk_widget_style_attach (widget);
- style = gtk_widget_get_style (widget);
- gtk_style_set_background (style, gdk_window, GTK_STATE_NORMAL);
- if (priv->frame)
- gtk_style_set_background (style, priv->frame, GTK_STATE_NORMAL);
if (priv->transient_parent &&
gtk_widget_get_realized (GTK_WIDGET (priv->transient_parent)))
if (priv->wm_role)
gdk_window_set_role (gdk_window, priv->wm_role);
-
+
if (!priv->decorated)
gdk_window_set_decorations (gdk_window, 0);
-
+
if (!priv->deletable)
gdk_window_set_functions (gdk_window, GDK_FUNC_ALL | GDK_FUNC_CLOSE);
-
+
if (gtk_window_get_skip_pager_hint (window))
gdk_window_set_skip_pager_hint (gdk_window, TRUE);
-
+
if (gtk_window_get_skip_taskbar_hint (window))
gdk_window_set_skip_taskbar_hint (gdk_window, TRUE);
-
+
if (gtk_window_get_accept_focus (window))
gdk_window_set_accept_focus (gdk_window, TRUE);
else
gdk_window_set_accept_focus (gdk_window, FALSE);
-
+
if (gtk_window_get_focus_on_map (window))
gdk_window_set_focus_on_map (gdk_window, TRUE);
else
gdk_window_set_focus_on_map (gdk_window, FALSE);
-
+
if (priv->modal)
gdk_window_set_modal_hint (gdk_window, TRUE);
else
if (priv->startup_id)
{
#ifdef GDK_WINDOWING_X11
- guint32 timestamp = extract_time_from_startup_id (priv->startup_id);
- if (timestamp != GDK_CURRENT_TIME)
- gdk_x11_window_set_user_time (gdk_window, timestamp);
+ if (GDK_IS_X11_WINDOW (gdk_window))
+ {
+ guint32 timestamp = extract_time_from_startup_id (priv->startup_id);
+ if (timestamp != GDK_CURRENT_TIME)
+ gdk_x11_window_set_user_time (gdk_window, timestamp);
+ }
#endif
- if (!startup_id_is_fake (priv->startup_id))
+ if (!startup_id_is_fake (priv->startup_id))
gdk_window_set_startup_id (gdk_window, priv->startup_id);
}
+#ifdef GDK_WINDOWING_X11
+ if (priv->initial_timestamp != GDK_CURRENT_TIME)
+ {
+ if (GDK_IS_X11_WINDOW (gdk_window))
+ gdk_x11_window_set_user_time (gdk_window, priv->initial_timestamp);
+ }
+#endif
+
/* Icons */
gtk_window_realize_icon (window);
-
+
if (priv->has_resize_grip)
resize_grip_create_window (window);
}
info->last.flags = 0;
}
- if (priv->frame)
- {
- gdk_window_set_user_data (priv->frame, NULL);
- gdk_window_destroy (priv->frame);
- priv->frame = NULL;
- }
-
/* Icons */
gtk_window_unrealize_icon (window);
GTK_WIDGET_CLASS (gtk_window_parent_class)->unrealize (widget);
}
-static GdkWindowEdge
-get_grip_edge (GtkWidget *widget)
+static GtkJunctionSides
+get_grip_junction (GtkWidget *widget)
{
- return gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR
- ? GDK_WINDOW_EDGE_SOUTH_EAST
- : GDK_WINDOW_EDGE_SOUTH_WEST;
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
+ return GTK_JUNCTION_CORNER_BOTTOMRIGHT;
+ else
+ return GTK_JUNCTION_CORNER_BOTTOMLEFT;
}
static gboolean
display = gtk_widget_get_display (widget);
cursor = gdk_cursor_new_for_display (display, cursor_type);
gdk_window_set_cursor (priv->grip_window, cursor);
- gdk_cursor_unref (cursor);
+ g_object_unref (cursor);
}
else
gdk_window_set_cursor (priv->grip_window, NULL);
width = gdk_window_get_width (priv->grip_window);
height = gdk_window_get_height (priv->grip_window);
- surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height);
cr = cairo_create (surface);
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
cairo_paint (cr);
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
- if (get_grip_edge (GTK_WIDGET (window)) == GDK_WINDOW_EDGE_SOUTH_EAST)
+ if (get_grip_junction (GTK_WIDGET (window)) & GTK_JUNCTION_CORNER_BOTTOMRIGHT)
{
cairo_move_to (cr, width, 0.0);
cairo_line_to (cr, width, height);
rect.width, rect.height);
}
+/* _gtk_window_set_allocation:
+ * @window: a #GtkWindow
+ * @allocation: the new allocation
+ *
+ * This function is like gtk_widget_set_allocation()
+ * but does the necessary extra work to update
+ * the resize grip positioning, etc.
+ *
+ * Call this instead of gtk_widget_set_allocation()
+ * when overriding ::size_allocate in a GtkWindow
+ * subclass without chaining up.
+ */
+void
+_gtk_window_set_allocation (GtkWindow *window,
+ GtkAllocation *allocation)
+{
+ GtkWidget *widget = (GtkWidget *)window;
+
+ gtk_widget_set_allocation (widget, allocation);
+
+ if (gtk_widget_get_realized (widget))
+ {
+ /* If it's not a toplevel we're embedded, we need to resize
+ * the window's window and skip the grip.
+ */
+ if (!gtk_widget_is_toplevel (widget))
+ {
+ gdk_window_move_resize (gtk_widget_get_window (widget),
+ allocation->x, allocation->y,
+ allocation->width, allocation->height);
+ }
+ else
+ {
+ update_grip_visibility (window);
+ set_grip_position (window);
+ }
+ }
+}
+
static void
gtk_window_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+ GtkAllocation *allocation)
{
GtkWindow *window = GTK_WINDOW (widget);
- GtkWindowPrivate *priv = window->priv;
GtkAllocation child_allocation;
GtkWidget *child;
guint border_width;
- gtk_widget_set_allocation (widget, allocation);
+ _gtk_window_set_allocation (window, allocation);
child = gtk_bin_get_child (&(window->bin));
if (child && gtk_widget_get_visible (child))
border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
child_allocation.x = border_width;
child_allocation.y = border_width;
- child_allocation.width =
- MAX (1, (gint)allocation->width - child_allocation.x * 2);
- child_allocation.height =
- MAX (1, (gint)allocation->height - child_allocation.y * 2);
+ child_allocation.width = MAX (1, allocation->width - border_width * 2);
+ child_allocation.height = MAX (1, allocation->height - border_width * 2);
gtk_widget_size_allocate (child, &child_allocation);
}
-
- if (gtk_widget_get_realized (widget))
- {
- if (priv->frame)
- gdk_window_resize (priv->frame,
- allocation->width + priv->frame_left + priv->frame_right,
- allocation->height + priv->frame_top + priv->frame_bottom);
- update_grip_visibility (window);
- set_grip_position (window);
- }
-}
-
-static gint
-gtk_window_event (GtkWidget *widget, GdkEvent *event)
-{
- GtkWindow *window = GTK_WINDOW (widget);
- GtkWindowPrivate *priv = window->priv;
- gboolean return_val;
-
- if (priv->frame && (event->any.window == priv->frame))
- {
- if ((event->type != GDK_KEY_PRESS) &&
- (event->type != GDK_KEY_RELEASE) &&
- (event->type != GDK_FOCUS_CHANGE))
- {
- g_signal_stop_emission_by_name (widget, "event");
- return_val = FALSE;
- g_signal_emit (widget, window_signals[FRAME_EVENT], 0, event, &return_val);
- return TRUE;
- }
- else
- {
- g_object_unref (event->any.window);
- event->any.window = g_object_ref (gtk_widget_get_window (widget));
- }
- }
-
- return FALSE;
-}
-
-static gboolean
-gtk_window_frame_event (GtkWindow *window, GdkEvent *event)
-{
- GtkWindowPrivate *priv = window->priv;
- GdkEventConfigure *configure_event;
- GdkRectangle rect;
-
- switch (event->type)
- {
- case GDK_CONFIGURE:
- configure_event = (GdkEventConfigure *)event;
-
- /* Invalidate the decorations */
- rect.x = 0;
- rect.y = 0;
- rect.width = configure_event->width;
- rect.height = configure_event->height;
-
- gdk_window_invalidate_rect (priv->frame, &rect, FALSE);
-
- /* Pass on the (modified) configure event */
- configure_event->width -= priv->frame_left + priv->frame_right;
- configure_event->height -= priv->frame_top + priv->frame_bottom;
- return gtk_window_configure_event (GTK_WIDGET (window), configure_event);
- break;
- default:
- break;
- }
- return FALSE;
}
static gint
GtkWindowPrivate *priv = window->priv;
gboolean expected_reply = priv->configure_request_count > 0;
+ if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+ {
+ if (GTK_WIDGET_CLASS (gtk_window_parent_class)->configure_event)
+ return GTK_WIDGET_CLASS (gtk_window_parent_class)->configure_event (widget, event);
+
+ return FALSE;
+ }
+
/* priv->configure_request_count incremented for each
* configure request, and decremented to a min of 0 for
* each configure notify.
(allocation.width == event->width &&
allocation.height == event->height))
{
- gdk_window_configure_finished (gtk_widget_get_window (widget));
return TRUE;
}
/*
* If we do need to resize, we do that by:
- * - filling in widget->allocation with the new size
* - setting configure_notify_received to TRUE
* for use in gtk_window_move_resize()
* - queueing a resize, leading to invocation of
priv->configure_notify_received = TRUE;
- allocation.width = event->width;
- allocation.height = event->height;
- gtk_widget_set_allocation (widget, &allocation);
-
gdk_window_invalidate_rect (gtk_widget_get_window (widget), NULL, FALSE); // XXX - What was this for again?
_gtk_container_queue_resize (GTK_CONTAINER (widget));
{
update_grip_visibility (GTK_WINDOW (widget));
+ if (event->changed_mask & GDK_WINDOW_STATE_FOCUSED)
+ ensure_state_flag_backdrop (widget);
+
return FALSE;
}
}
static void
-gtk_window_style_set (GtkWidget *widget,
- GtkStyle *style)
+gtk_window_style_updated (GtkWidget *widget)
{
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
GdkRectangle rect;
+ GTK_WIDGET_CLASS (gtk_window_parent_class)->style_updated (widget);
+
if (priv->grip_window != NULL && gtk_window_get_resize_grip_area (window, &rect))
{
gdk_window_move_resize (priv->grip_window,
rect.width, rect.height);
set_grip_shape (window);
- gtk_widget_queue_resize (widget);
}
}
GdkWindowAttr attributes;
gint attributes_mask;
GdkRectangle rect;
+ GdkRGBA transparent = {0, 0, 0, 0};
priv = window->priv;
widget = GTK_WIDGET (window);
priv->grip_window = gdk_window_new (gtk_widget_get_window (widget),
&attributes,
attributes_mask);
+ gdk_window_set_background_rgba (priv->grip_window, &transparent);
- gdk_window_set_user_data (priv->grip_window, widget);
+ gtk_widget_register_window (widget, priv->grip_window);
gdk_window_raise (priv->grip_window);
{
GtkWindowPrivate *priv = window->priv;
- gdk_window_set_user_data (priv->grip_window, NULL);
+ gtk_widget_unregister_window (GTK_WIDGET (window), priv->grip_window);
gdk_window_destroy (priv->grip_window);
priv->grip_window = NULL;
update_grip_visibility (window);
priv->has_resize_grip = value;
gtk_widget_queue_draw (widget);
- if (gtk_widget_get_realized (widget))
+ if (gtk_widget_get_realized (widget) &&
+ gtk_widget_is_toplevel (GTK_WIDGET (widget)))
{
if (priv->has_resize_grip && priv->grip_window == NULL)
resize_grip_create_window (window);
*
* Determines whether a resize grip is visible for the specified window.
*
- * Returns %TRUE if a resize grip exists and is visible.
+ * Returns: %TRUE if a resize grip exists and is visible
*
* Since: 3.0
*/
if (!priv->resizable)
return FALSE;
+ if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+ return FALSE;
+
if (gtk_widget_get_realized (widget))
{
GdkWindowState state;
*
* Determines whether the window may have a resize grip.
*
- * Returns: %TRUE if the window has a resize grip.
+ * Returns: %TRUE if the window has a resize grip
*
* Since: 3.0
*/
/**
* gtk_window_get_resize_grip_area:
* @window: a #GtkWindow
- * @rect: a pointer to a #GdkRectangle which we should store the
- * resize grip area.
+ * @rect: (out): a pointer to a #GdkRectangle which we should store
+ * the resize grip area
*
* If a window has a resize grip, this will retrieve the grip
* position, width and height into the specified #GdkRectangle.
*
- * Returns: %TRUE if the resize grip's area was retrieved.
+ * Returns: %TRUE if the resize grip's area was retrieved
*
* Since: 3.0
*/
gboolean
-gtk_window_get_resize_grip_area (GtkWindow *window,
+gtk_window_get_resize_grip_area (GtkWindow *window,
GdkRectangle *rect)
{
GtkWidget *widget = GTK_WIDGET (window);
GtkAllocation allocation;
- GtkStyle *style;
gint grip_width;
gint grip_height;
return FALSE;
gtk_widget_get_allocation (widget, &allocation);
- style = gtk_widget_get_style (widget);
gtk_widget_style_get (widget,
"resize-grip-width", &grip_width,
if (event->window == priv->grip_window)
{
if (get_drag_edge (widget, &edge))
- gtk_window_begin_resize_drag (GTK_WINDOW (widget),
- edge,
- event->button,
- event->x_root,
- event->y_root,
- event->time);
+ gdk_window_begin_resize_drag_for_device (gtk_widget_get_window (widget),
+ edge,
+ gdk_event_get_device ((GdkEvent *) event),
+ event->button,
+ event->x_root,
+ event->y_root,
+ event->time);
return TRUE;
}
GdkDevice *dev = d->data;
GdkEvent *fevent;
- if (dev->source != GDK_SOURCE_KEYBOARD)
+ if (gdk_device_get_source (dev) != GDK_SOURCE_KEYBOARD)
continue;
/* Skip non-master keyboards that haven't
g_object_unref (widget);
}
+static void
+maybe_set_mnemonics_visible (GtkWindow *window)
+{
+ GList *devices, *d;
+ GdkDeviceManager *device_manager;
+
+ device_manager = gdk_display_get_device_manager (gtk_widget_get_display (GTK_WIDGET (window)));
+ devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
+
+ for (d = devices; d; d = d->next)
+ {
+ GdkDevice *dev = d->data;
+
+ if (gdk_device_get_source (dev) == GDK_SOURCE_MOUSE)
+ {
+ GdkModifierType mask;
+
+ gdk_device_get_state (dev, gtk_widget_get_window (GTK_WIDGET (window)),
+ NULL, &mask);
+ if (window->priv->mnemonic_modifier == (mask & gtk_accelerator_get_default_mod_mask ()))
+ {
+ _gtk_window_set_auto_mnemonics_visible (window);
+ break;
+ }
+ }
+ }
+
+ g_list_free (devices);
+}
+
static gint
gtk_window_focus_in_event (GtkWidget *widget,
GdkEventFocus *event)
{
GtkWindow *window = GTK_WINDOW (widget);
+ gboolean auto_mnemonics;
/* It appears spurious focus in events can occur when
* the window is hidden. So we'll just check to see if
{
_gtk_window_set_has_toplevel_focus (window, TRUE);
_gtk_window_set_is_active (window, TRUE);
+
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-auto-mnemonics", &auto_mnemonics, NULL);
+ if (auto_mnemonics)
+ maybe_set_mnemonics_visible (window);
}
-
+
return FALSE;
}
return FALSE;
}
-static GdkAtom atom_rcfiles = GDK_NONE;
-static GdkAtom atom_iconthemes = GDK_NONE;
-
-static void
-send_client_message_to_embedded_windows (GtkWidget *widget,
- GdkAtom message_type)
-{
- GList *embedded_windows;
-
- embedded_windows = g_object_get_qdata (G_OBJECT (widget), quark_gtk_embedded);
- if (embedded_windows)
- {
- GdkEvent *send_event = gdk_event_new (GDK_CLIENT_EVENT);
- int i;
-
- for (i = 0; i < 5; i++)
- send_event->client.data.l[i] = 0;
- send_event->client.data_format = 32;
- send_event->client.message_type = message_type;
-
- while (embedded_windows)
- {
- GdkNativeWindow xid = GDK_GPOINTER_TO_NATIVE_WINDOW(embedded_windows->data);
- gdk_event_send_client_message_for_display (gtk_widget_get_display (widget), send_event, xid);
- embedded_windows = embedded_windows->next;
- }
-
- gdk_event_free (send_event);
- }
-}
-
-static gint
-gtk_window_client_event (GtkWidget *widget,
- GdkEventClient *event)
-{
- if (!atom_rcfiles)
- {
- atom_rcfiles = gdk_atom_intern_static_string ("_GTK_READ_RCFILES");
- atom_iconthemes = gdk_atom_intern_static_string ("_GTK_LOAD_ICONTHEMES");
- }
-
- if (event->message_type == atom_rcfiles)
- {
- send_client_message_to_embedded_windows (widget, atom_rcfiles);
- gtk_rc_reparse_all_for_settings (gtk_widget_get_settings (widget), FALSE);
- }
-
- if (event->message_type == atom_iconthemes)
- {
- send_client_message_to_embedded_windows (widget, atom_iconthemes);
- _gtk_icon_theme_check_reload (gtk_widget_get_display (widget));
- }
-
- return FALSE;
-}
-
static void
gtk_window_check_resize (GtkContainer *container)
{
- if (gtk_widget_get_visible (GTK_WIDGET (container)))
+ /* If the window is not toplevel anymore than it's embedded somewhere,
+ * so handle it like a normal window */
+ if (!gtk_widget_is_toplevel (GTK_WIDGET (container)))
+ GTK_CONTAINER_CLASS (gtk_window_parent_class)->check_resize (container);
+ else if (gtk_widget_get_visible (GTK_WIDGET (container)))
gtk_window_move_resize (GTK_WINDOW (container));
}
GtkWidget *old_focus_child;
GtkWidget *parent;
+ if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+ return GTK_WIDGET_CLASS (gtk_window_parent_class)->focus (widget, direction);
+
container = GTK_CONTAINER (widget);
window = GTK_WINDOW (widget);
priv = window->priv;
gtk_window_move_focus (GtkWidget *widget,
GtkDirectionType dir)
{
+ if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+ {
+ GTK_WIDGET_CLASS (gtk_window_parent_class)->move_focus (widget, dir);
+ return;
+ }
+
gtk_widget_child_focus (widget, dir);
if (! gtk_container_get_focus_child (GTK_CONTAINER (widget)))
}
}
-
-static void
-gtk_window_get_preferred_width (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
-{
- GtkWindow *window;
- GtkWidget *child;
- guint border_width;
-
- window = GTK_WINDOW (widget);
- child = gtk_bin_get_child (GTK_BIN (window));
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
- *minimum_size = border_width * 2;
- *natural_size = border_width * 2;
-
- if (child && gtk_widget_get_visible (child))
- {
- gint child_min, child_nat;
- gtk_widget_get_preferred_width (child, &child_min, &child_nat);
-
- *minimum_size += child_min;
- *natural_size += child_nat;
- }
-}
-
-static void
-gtk_window_get_preferred_height (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
-{
- GtkWindow *window;
- GtkWidget *child;
- guint border_width;
-
- window = GTK_WINDOW (widget);
- child = gtk_bin_get_child (GTK_BIN (window));
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
- *minimum_size = border_width * 2;
- *natural_size = border_width * 2;
-
- if (child && gtk_widget_get_visible (child))
- {
- gint child_min, child_nat;
- gtk_widget_get_preferred_height (child, &child_min, &child_nat);
-
- *minimum_size += child_min;
- *natural_size += child_nat;
- }
-}
-
-
/**
* _gtk_window_unset_focus_and_default:
* @window: a #GtkWindow
static void
geometry_size_to_pixels (GdkGeometry *geometry,
guint flags,
- guint *width,
- guint *height)
+ gint *width,
+ gint *height)
{
gint base_width = 0;
gint base_height = 0;
gtk_window_compute_configure_request_size (GtkWindow *window,
GdkGeometry *geometry,
guint flags,
- guint *width,
- guint *height)
+ gint *width,
+ gint *height)
{
GtkWindowPrivate *priv = window->priv;
- GtkRequisition requisition;
GtkWindowGeometryInfo *info;
- GtkWidget *widget;
/* Preconditions:
* - we've done a size request
*/
- widget = GTK_WIDGET (window);
-
info = gtk_window_get_geometry_info (window, FALSE);
if (priv->need_default_size)
{
- gtk_widget_get_preferred_size (widget, &requisition, NULL);
-
- /* Default to requisition */
- *width = requisition.width;
- *height = requisition.height;
+ gtk_window_guess_default_size (window, width, height);
/* If window is empty so requests 0, default to random nonzero size */
if (*width == 0 && *height == 0)
*height = 200;
}
- /* Override requisition with default size */
+ /* Override with default size */
if (info)
{
{
GtkAllocation allocation;
- gtk_widget_get_allocation (widget, &allocation);
+ gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
/* Default to keeping current size */
*width = allocation.width;
info->resize_height > 0 ? height : NULL);
}
- /* Don't ever request zero width or height, its not supported by
+ /* Don't ever request zero width or height, it's not supported by
gdk. The size allocation code will round it to 1 anyway but if
we do it then the value returned from this function will is
not comparable to the size allocation read from the GtkWindow. */
device_manager = gdk_display_get_device_manager (display);
pointer = gdk_device_manager_get_client_pointer (device_manager);
- gdk_display_get_device_state (display, pointer,
- &pointer_screen,
- &px, &py, NULL);
+ gdk_device_get_position (pointer,
+ &pointer_screen,
+ &px, &py);
if (pointer_screen == window_screen)
monitor_num = gdk_screen_get_monitor_at_point (pointer_screen, px, py);
int monitor_num;
monitor_num = get_monitor_containing_pointer (window);
-
+
if (monitor_num == -1)
monitor_num = get_center_monitor_of_window (window);
- gdk_screen_get_monitor_geometry (gtk_window_check_screen (window),
- monitor_num, &monitor);
-
+ gdk_screen_get_monitor_workarea (gtk_window_check_screen (window),
+ monitor_num, &monitor);
+
*x = (monitor.width - w) / 2 + monitor.x;
*y = (monitor.height - h) / 2 + monitor.y;
GdkGeometry new_geometry;
guint new_flags;
int w, h;
- GtkWidget *widget;
GtkWindowPosition pos;
GtkWidget *parent_widget;
GtkWindowGeometryInfo *info;
GdkScreen *screen;
int x, y;
-
- widget = GTK_WIDGET (window);
screen = gtk_window_check_screen (window);
gtk_window_compute_hints (window, &new_geometry, &new_flags);
gtk_window_compute_configure_request_size (window,
- &new_geometry, new_flags,
- (guint *)&w, (guint *)&h);
+ &new_geometry, new_flags,
+ &w, &h);
gtk_window_constrain_size (window,
&new_geometry, new_flags,
&w, &h);
parent_widget = (GtkWidget*) priv->transient_parent;
-
+
pos = get_effective_position (window);
info = gtk_window_get_geometry_info (window, FALSE);
-
+
/* by default, don't change position requested */
if (info)
{
*
* Not sure how to go about that.
*/
-
switch (pos)
{
/* here we are only handling CENTER_ALWAYS
case GTK_WIN_POS_CENTER:
center_window_on_monitor (window, w, h, &x, &y);
break;
-
+
case GTK_WIN_POS_CENTER_ON_PARENT:
{
GtkAllocation allocation;
gint monitor_num;
GdkRectangle monitor;
gint ox, oy;
-
+
g_assert (gtk_widget_get_mapped (parent_widget)); /* established earlier */
gdk_window = gtk_widget_get_window (parent_widget);
{
gint screen_width = gdk_screen_get_width (screen);
gint screen_height = gdk_screen_get_height (screen);
- gint monitor_num;
- GdkRectangle monitor;
+ gint monitor_num;
+ GdkRectangle monitor;
GdkDisplay *display;
GdkDeviceManager *device_manager;
GdkDevice *pointer;
device_manager = gdk_display_get_device_manager (display);
pointer = gdk_device_manager_get_client_pointer (device_manager);
- gdk_display_get_device_state (display, pointer,
- &pointer_screen,
- &px, &py, NULL);
+ gdk_device_get_position (pointer,
+ &pointer_screen,
+ &px, &py);
if (pointer_screen == screen)
monitor_num = gdk_screen_get_monitor_at_point (screen, px, py);
else
monitor_num = -1;
-
+
x = px - w / 2;
y = py - h / 2;
x = CLAMP (x, 0, screen_width - w);
y = info->initial_y;
gtk_window_constrain_position (window, w, h, &x, &y);
}
-
+
request->x = x;
request->y = y;
request->width = w;
GtkWindowLastGeometryInfo saved_last_info;
widget = GTK_WIDGET (window);
+
gdk_window = gtk_widget_get_window (widget);
container = GTK_CONTAINER (widget);
info = gtk_window_get_geometry_info (window, TRUE);
&new_geometry,
new_flags);
- gtk_widget_get_allocation (widget, &allocation);
+ allocation.x = 0;
+ allocation.y = 0;
+ allocation.width = gdk_window_get_width (gdk_window);
+ allocation.height = gdk_window_get_height (gdk_window);
/* handle resizing/moving and widget tree allocation
*/
set_grip_position (window);
update_grip_visibility (window);
- gdk_window_process_updates (gdk_window, TRUE);
-
- gdk_window_configure_finished (gdk_window);
-
/* If the configure request changed, it means that
* we either:
* 1) coincidentally changed hints or widget properties
/* Now send the configure request */
if (configure_request_pos_changed)
- {
- if (priv->frame)
- {
- gdk_window_move_resize (priv->frame,
- new_request.x - priv->frame_left,
- new_request.y - priv->frame_top,
- new_request.width + priv->frame_left + priv->frame_right,
- new_request.height + priv->frame_top + priv->frame_bottom);
- gdk_window_resize (gdk_window,
- new_request.width, new_request.height);
- }
- else
- gdk_window_move_resize (gdk_window,
- new_request.x, new_request.y,
- new_request.width, new_request.height);
- }
+ {
+ gdk_window_move_resize (gdk_window,
+ new_request.x, new_request.y,
+ new_request.width, new_request.height);
+ }
else /* only size changed */
- {
- if (priv->frame)
- gdk_window_resize (priv->frame,
- new_request.width + priv->frame_left + priv->frame_right,
- new_request.height + priv->frame_top + priv->frame_bottom);
- gdk_window_resize (gdk_window,
- new_request.width, new_request.height);
- }
+ {
+ gdk_window_resize (gdk_window,
+ new_request.width, new_request.height);
+ }
if (priv->type == GTK_WINDOW_POPUP)
{
/* Handle any position changes.
*/
if (configure_request_pos_changed)
- {
- if (priv->frame)
- {
- gdk_window_move (priv->frame,
- new_request.x - priv->frame_left,
- new_request.y - priv->frame_top);
- }
- else
- gdk_window_move (gdk_window,
- new_request.x, new_request.y);
- }
+ {
+ gdk_window_move (gdk_window,
+ new_request.x, new_request.y);
+ }
/* And run the resize queue.
*/
extra_width = requisition.width - TEMPORARY_SIZE;
extra_height = requisition.height - TEMPORARY_SIZE;
- if (extra_width < 0 || extra_width < 0)
+ if (extra_width < 0 || extra_height < 0)
{
g_warning("Toplevel size doesn't seem to directly depend on the "
"size of the geometry widget from gtk_window_set_geometry_hints(). "
}
}
+ /* Please use a good size for unresizable widgets, not the minimum one. */
+ if (!priv->resizable)
+ gtk_window_guess_default_size (window, &requisition.width, &requisition.height);
+
if (*new_flags & GDK_HINT_MIN_SIZE)
{
if (new_geometry->min_width < 0)
cairo_t *cr)
{
GtkWindowPrivate *priv = GTK_WINDOW (widget)->priv;
+ GtkStyleContext *context;
gboolean ret = FALSE;
- if (!gtk_widget_get_app_paintable (widget))
- gtk_paint_flat_box (gtk_widget_get_style (widget),
- cr,
- GTK_STATE_NORMAL,
- GTK_SHADOW_NONE, widget, "base",
- 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
+ context = gtk_widget_get_style_context (widget);
+
+ if (!gtk_widget_get_app_paintable (widget) &&
+ gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
+ {
+ gtk_render_background (context, cr, 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+ }
if (GTK_WIDGET_CLASS (gtk_window_parent_class)->draw)
ret = GTK_WIDGET_CLASS (gtk_window_parent_class)->draw (widget, cr);
- if (priv->grip_window != NULL &&
+ if (priv->grip_window &&
gtk_cairo_should_draw_window (cr, priv->grip_window))
{
GdkRectangle rect;
+ gtk_style_context_save (context);
cairo_save (cr);
+
gtk_cairo_transform_to_window (cr, widget, priv->grip_window);
gtk_window_get_resize_grip_area (GTK_WINDOW (widget), &rect);
- gtk_paint_resize_grip (gtk_widget_get_style (widget),
- cr,
- gtk_widget_get_state (widget),
- widget,
- "statusbar",
- get_grip_edge (widget),
- 0, 0,
- rect.width, rect.height);
+
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BACKGROUND);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_GRIP);
+ gtk_style_context_set_junction_sides (context, get_grip_junction (widget));
+ gtk_render_handle (context, cr, 0, 0, rect.width, rect.height);
+
cairo_restore (cr);
+ gtk_style_context_restore (context);
}
return ret;
}
-/**
- * gtk_window_set_has_frame:
- * @window: a #GtkWindow
- * @setting: a boolean
- *
- * (Note: this is a special-purpose function for the framebuffer port,
- * that causes GTK+ to draw its own window border. For most applications,
- * you want gtk_window_set_decorated() instead, which tells the window
- * manager whether to draw the window border.)
- *
- * If this function is called on a window with setting of %TRUE, before
- * it is realized or showed, it will have a "frame" window around
- * @window->window, accessible in @window->frame. Using the signal
- * frame_event you can receive all events targeted at the frame.
- *
- * This function is used by the linux-fb port to implement managed
- * windows, but it could conceivably be used by X-programs that
- * want to do their own window decorations.
- *
- **/
-void
-gtk_window_set_has_frame (GtkWindow *window,
- gboolean setting)
-{
- GtkWindowPrivate *priv;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
- g_return_if_fail (!gtk_widget_get_realized (GTK_WIDGET (window)));
-
- priv = window->priv;
-
- priv->has_frame = setting != FALSE;
-}
-
-/**
- * gtk_window_get_has_frame:
- * @window: a #GtkWindow
- *
- * Accessor for whether the window has a frame window exterior to
- * @window->window. Gets the value set by gtk_window_set_has_frame ().
- *
- * Return value: %TRUE if a frame has been added to the window
- * via gtk_window_set_has_frame().
- **/
-gboolean
-gtk_window_get_has_frame (GtkWindow *window)
-{
- g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
-
- return window->priv->has_frame;
-}
-
-/**
- * gtk_window_set_frame_dimensions:
- * @window: a #GtkWindow that has a frame
- * @left: The width of the left border
- * @top: The height of the top border
- * @right: The width of the right border
- * @bottom: The height of the bottom border
- *
- * (Note: this is a special-purpose function intended for the framebuffer
- * port; see gtk_window_set_has_frame(). It will have no effect on the
- * window border drawn by the window manager, which is the normal
- * case when using the X Window system.)
- *
- * For windows with frames (see gtk_window_set_has_frame()) this function
- * can be used to change the size of the frame border.
- **/
-void
-gtk_window_set_frame_dimensions (GtkWindow *window,
- gint left,
- gint top,
- gint right,
- gint bottom)
-{
- GtkWindowPrivate *priv;
- GtkAllocation allocation;
- GtkWidget *widget;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- priv = window->priv;
- widget = GTK_WIDGET (window);
-
- if (priv->frame_left == left &&
- priv->frame_top == top &&
- priv->frame_right == right &&
- priv->frame_bottom == bottom)
- return;
-
- priv->frame_left = left;
- priv->frame_top = top;
- priv->frame_right = right;
- priv->frame_bottom = bottom;
-
- if (gtk_widget_get_realized (widget) && priv->frame)
- {
- gint width, height;
- gtk_widget_get_allocation (widget, &allocation);
-
- width = allocation.width + left + right;
- height = allocation.height + top + bottom;
- gdk_window_resize (priv->frame, width, height);
- gtk_decorated_window_move_resize_window (window,
- left, top,
- allocation.width,
- allocation.height);
- }
-}
-
/**
* gtk_window_present:
* @window: a #GtkWindow
gtk_window_present_with_time (GtkWindow *window,
guint32 timestamp)
{
+ GtkWindowPrivate *priv;
GtkWidget *widget;
GdkWindow *gdk_window;
g_return_if_fail (GTK_IS_WINDOW (window));
+ priv = window->priv;
widget = GTK_WIDGET (window);
if (gtk_widget_get_visible (widget))
if (timestamp == GDK_CURRENT_TIME)
{
#ifdef GDK_WINDOWING_X11
- GdkDisplay *display;
+ if (GDK_IS_X11_WINDOW(gdk_window))
+ {
+ GdkDisplay *display;
- display = gtk_widget_get_display (GTK_WIDGET (window));
- timestamp = gdk_x11_display_get_user_time (display);
-#else
- timestamp = gtk_get_current_event_time ();
+ display = gtk_widget_get_display (GTK_WIDGET (window));
+ timestamp = gdk_x11_display_get_user_time (display);
+ }
+ else
#endif
+ timestamp = gtk_get_current_event_time ();
}
gdk_window_focus (gdk_window, timestamp);
}
else
{
+ priv->initial_timestamp = timestamp;
gtk_widget_show (widget);
}
}
priv->iconify_initially = TRUE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_iconify (toplevel);
priv->iconify_initially = FALSE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_deiconify (toplevel);
priv->stick_initially = TRUE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_stick (toplevel);
priv->stick_initially = FALSE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_unstick (toplevel);
priv->maximize_initially = TRUE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_maximize (toplevel);
priv->maximize_initially = FALSE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_unmaximize (toplevel);
priv->fullscreen_initially = TRUE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_fullscreen (toplevel);
priv->fullscreen_initially = FALSE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_unfullscreen (toplevel);
if (setting)
priv->below_initially = FALSE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_set_keep_above (toplevel, setting);
if (setting)
priv->above_initially = FALSE;
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
if (toplevel != NULL)
gdk_window_set_keep_below (toplevel, setting);
if (priv->resizable != resizable)
{
- priv->resizable = (resizable != FALSE);
+ priv->resizable = resizable;
update_grip_visibility (window);
gint root_y,
guint32 timestamp)
{
- GtkWindowPrivate *priv;
GtkWidget *widget;
GdkWindow *toplevel;
-
+
g_return_if_fail (GTK_IS_WINDOW (window));
widget = GTK_WIDGET (window);
g_return_if_fail (gtk_widget_get_visible (widget));
- priv = window->priv;
-
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
gdk_window_begin_resize_drag (toplevel,
edge, button,
timestamp);
}
-/**
- * gtk_window_get_frame_dimensions:
- * @window: a #GtkWindow
- * @left: (out) (allow-none): location to store the width of the frame at the left, or %NULL
- * @top: (out) (allow-none): location to store the height of the frame at the top, or %NULL
- * @right: (out) (allow-none): location to store the width of the frame at the returns, or %NULL
- * @bottom: (out) (allow-none): location to store the height of the frame at the bottom, or %NULL
- *
- * (Note: this is a special-purpose function intended for the
- * framebuffer port; see gtk_window_set_has_frame(). It will not
- * return the size of the window border drawn by the <link
- * linkend="gtk-X11-arch">window manager</link>, which is the normal
- * case when using a windowing system. See
- * gdk_window_get_frame_extents() to get the standard window border
- * extents.)
- *
- * Retrieves the dimensions of the frame window for this toplevel.
- * See gtk_window_set_has_frame(), gtk_window_set_frame_dimensions().
- **/
-void
-gtk_window_get_frame_dimensions (GtkWindow *window,
- gint *left,
- gint *top,
- gint *right,
- gint *bottom)
-{
- GtkWindowPrivate *priv;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- priv = window->priv;
-
- if (left)
- *left = priv->frame_left;
- if (top)
- *top = priv->frame_top;
- if (right)
- *right = priv->frame_right;
- if (bottom)
- *bottom = priv->frame_bottom;
-}
-
/**
* gtk_window_begin_move_drag:
* @window: a #GtkWindow
gint root_y,
guint32 timestamp)
{
- GtkWindowPrivate *priv;
GtkWidget *widget;
GdkWindow *toplevel;
-
+
g_return_if_fail (GTK_IS_WINDOW (window));
widget = GTK_WIDGET (window);
g_return_if_fail (gtk_widget_get_visible (widget));
- priv = window->priv;
-
- if (priv->frame)
- toplevel = priv->frame;
- else
- toplevel = gtk_widget_get_window (widget);
+ toplevel = gtk_widget_get_window (widget);
gdk_window_begin_move_drag (toplevel,
button,
timestamp);
}
-/**
+/**
* gtk_window_set_screen:
* @window: a #GtkWindow.
* @screen: a #GdkScreen.
GtkWidget *widget;
GdkScreen *previous_screen;
gboolean was_mapped;
-
+
g_return_if_fail (GTK_IS_WINDOW (window));
g_return_if_fail (GDK_IS_SCREEN (screen));
gtk_widget_unmap (widget);
if (gtk_widget_get_realized (widget))
gtk_widget_unrealize (widget);
-
+
gtk_window_free_key_hash (window);
priv->screen = screen;
gtk_widget_reset_rc_styles (widget);
if (screen != previous_screen)
{
- g_signal_handlers_disconnect_by_func (previous_screen,
- gtk_window_on_composited_changed, window);
- g_signal_connect (screen, "composited-changed",
- G_CALLBACK (gtk_window_on_composited_changed), window);
-
+ if (previous_screen)
+ {
+ g_signal_handlers_disconnect_by_func (previous_screen,
+ gtk_window_on_composited_changed, window);
+#ifdef GDK_WINDOWING_X11
+ g_signal_handlers_disconnect_by_func (gtk_settings_get_for_screen (previous_screen),
+ gtk_window_on_theme_variant_changed, window);
+#endif
+ }
+ g_signal_connect (screen, "composited-changed",
+ G_CALLBACK (gtk_window_on_composited_changed), window);
+#ifdef GDK_WINDOWING_X11
+ g_signal_connect (gtk_settings_get_for_screen (screen),
+ "notify::gtk-application-prefer-dark-theme",
+ G_CALLBACK (gtk_window_on_theme_variant_changed), window);
+#endif
+
_gtk_widget_propagate_screen_changed (widget, previous_screen);
_gtk_widget_propagate_composited_changed (widget);
}
gtk_widget_map (widget);
}
+static void
+gtk_window_set_theme_variant (GtkWindow *window)
+{
+#ifdef GDK_WINDOWING_X11
+ GdkWindow *gdk_window;
+ gboolean dark_theme_requested;
+
+ g_object_get (gtk_settings_get_for_screen (window->priv->screen),
+ "gtk-application-prefer-dark-theme", &dark_theme_requested,
+ NULL);
+
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+ if (GDK_IS_X11_WINDOW (gdk_window))
+ gdk_x11_window_set_theme_variant (gdk_window,
+ dark_theme_requested ? "dark" : NULL);
+#endif
+}
+
+#ifdef GDK_WINDOWING_X11
+static void
+gtk_window_on_theme_variant_changed (GtkSettings *settings,
+ GParamSpec *pspec,
+ GtkWindow *window)
+{
+ if (window->priv->type == GTK_WINDOW_TOPLEVEL)
+ gtk_window_set_theme_variant (window);
+}
+#endif
+
static void
gtk_window_on_composited_changed (GdkScreen *screen,
GtkWindow *window)
return window->priv->has_toplevel_focus;
}
+
+/**
+ * SECTION:gtkwindowgroup
+ * @Short_description: Limit the effect of grabs
+ * @Title: GtkWindowGroup
+ *
+ * #GtkWindowGroup objects are referenced by each window in the group,
+ * so once you have added all windows to a #GtkWindowGroup, you can drop
+ * the initial reference to the window group with g_object_unref(). If the
+ * windows in the window group are subsequently destroyed, then they will
+ * be removed from the window group and drop their references on the window
+ * group; when all window have been removed, the window group will be
+ * freed.
+ */
+
+G_DEFINE_TYPE (GtkWindowGroup, gtk_window_group, G_TYPE_OBJECT)
+
static void
-gtk_window_group_class_init (GtkWindowGroupClass *klass)
+gtk_window_group_init (GtkWindowGroup *group)
{
- g_type_class_add_private (klass, sizeof (GtkWindowGroupPrivate));
+ group->priv = G_TYPE_INSTANCE_GET_PRIVATE (group,
+ GTK_TYPE_WINDOW_GROUP,
+ GtkWindowGroupPrivate);
}
-GType
-gtk_window_group_get_type (void)
+static void
+gtk_window_group_class_init (GtkWindowGroupClass *klass)
{
- static GType window_group_type = 0;
-
- if (!window_group_type)
- {
- const GTypeInfo window_group_info =
- {
- sizeof (GtkWindowGroupClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_window_group_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkWindowGroup),
- 0, /* n_preallocs */
- (GInstanceInitFunc) NULL,
- };
-
- window_group_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkWindowGroup"),
- &window_group_info, 0);
- }
-
- return window_group_type;
+ g_type_class_add_private (klass, sizeof (GtkWindowGroupPrivate));
}
/**
static void
window_group_cleanup_grabs (GtkWindowGroup *group,
- GtkWindow *window)
+ GtkWindow *window)
{
GtkWindowGroupPrivate *priv;
GtkDeviceGrabInfo *info;
GSList *tmp_list;
GSList *to_remove = NULL;
- tmp_list = group->grabs;
+ priv = group->priv;
+
+ tmp_list = priv->grabs;
while (tmp_list)
{
if (gtk_widget_get_toplevel (tmp_list->data) == (GtkWidget*) window)
to_remove = g_slist_delete_link (to_remove, to_remove);
}
- priv = GTK_WINDOW_GROUP_GET_PRIVATE (group);
tmp_list = priv->device_grabs;
while (tmp_list)
*
* Returns a list of the #GtkWindows that belong to @window_group.
*
- * Returns: (element-type GtkWidget) (transfer container): A newly-allocated list of
- * windows inside the group.
+ * Returns: (element-type GtkWindow) (transfer container): A
+ * newly-allocated list of windows inside the group.
*
* Since: 2.14
**/
group_windows = g_list_prepend (group_windows, window);
}
+ g_list_free (toplevels);
+
return g_list_reverse (group_windows);
}
* Gets the current grab widget of the given group,
* see gtk_grab_add().
*
- * Returns: the current grab widget of the group
+ * Returns: (transfer none): the current grab widget of the group
*
* Since: 2.22
*/
{
g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
- if (window_group->grabs)
- return GTK_WIDGET (window_group->grabs->data);
+ if (window_group->priv->grabs)
+ return GTK_WIDGET (window_group->priv->grabs->data);
return NULL;
}
+void
+_gtk_window_group_add_grab (GtkWindowGroup *window_group,
+ GtkWidget *widget)
+{
+ GtkWindowGroupPrivate *priv;
+
+ priv = window_group->priv;
+ priv->grabs = g_slist_prepend (priv->grabs, widget);
+}
+
+void
+_gtk_window_group_remove_grab (GtkWindowGroup *window_group,
+ GtkWidget *widget)
+{
+ GtkWindowGroupPrivate *priv;
+
+ priv = window_group->priv;
+ priv->grabs = g_slist_remove (priv->grabs, widget);
+}
+
+
void
_gtk_window_group_add_device_grab (GtkWindowGroup *window_group,
GtkWidget *widget,
GtkWindowGroupPrivate *priv;
GtkDeviceGrabInfo *info;
- priv = GTK_WINDOW_GROUP_GET_PRIVATE (window_group);
+ priv = window_group->priv;
info = g_slice_new0 (GtkDeviceGrabInfo);
info->widget = widget;
GSList *list, *node = NULL;
GdkDevice *other_device;
- priv = GTK_WINDOW_GROUP_GET_PRIVATE (window_group);
+ priv = window_group->priv;
other_device = gdk_device_get_associated_device (device);
list = priv->device_grabs;
*
* Returns the current grab widget for @device, or %NULL if none.
*
- * Returns: The grab widget, or %NULL
+ * Returns: (transfer none): The grab widget, or %NULL
*
* Since: 3.0
*/
g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
- priv = GTK_WINDOW_GROUP_GET_PRIVATE (window_group);
+ priv = window_group->priv;
list = priv->device_grabs;
other_device = gdk_device_get_associated_device (device);
GdkDevice *other_device;
GSList *list;
- priv = GTK_WINDOW_GROUP_GET_PRIVATE (window_group);
+ priv = window_group->priv;
other_device = gdk_device_get_associated_device (device);
list = priv->device_grabs;
* _gtk_window_set_is_toplevel:
* @window: a #GtkWindow
* @is_toplevel: %TRUE if the window is still a real toplevel (nominally a
- * parent of the root window); %FALSE if it is not (for example, for an
+ * child of the root window); %FALSE if it is not (for example, for an
* in-process, parented GtkPlug)
*
* Internal function used by #GtkPlug when it gets parented/unparented by a
- * #GtkSocket. This keeps the @window's #GTK_TOPLEVEL flag in sync with the
- * global list of toplevel windows.
+ * #GtkSocket. This keeps the @window's #GTK_WINDOW_TOPLEVEL flag in sync
+ * with the global list of toplevel windows.
*/
void
_gtk_window_set_is_toplevel (GtkWindow *window,
- gboolean is_toplevel)
+ gboolean is_toplevel)
{
GtkWidget *widget;
+ GtkWidget *toplevel;
widget = GTK_WIDGET (window);
if (is_toplevel)
{
+ /* Pass through regular pathways of an embedded toplevel
+ * to go through unmapping and hiding the widget before
+ * becomming a toplevel again.
+ *
+ * We remain hidden after becomming toplevel in order to
+ * avoid problems during an embedded toplevel's dispose cycle
+ * (When a toplevel window is shown it tries to grab focus again,
+ * this causes problems while disposing).
+ */
+ gtk_widget_hide (widget);
+
+ /* Save the toplevel this widget was previously anchored into before
+ * propagating a hierarchy-changed.
+ *
+ * Usually this happens by way of gtk_widget_unparent() and we are
+ * already unanchored at this point, just adding this clause incase
+ * things happen differently.
+ */
+ toplevel = gtk_widget_get_toplevel (widget);
+ if (!gtk_widget_is_toplevel (toplevel))
+ toplevel = NULL;
+
_gtk_widget_set_is_toplevel (widget, TRUE);
+
+ /* When a window becomes toplevel after being embedded and anchored
+ * into another window we need to unset its anchored flag so that
+ * the hierarchy changed signal kicks in properly.
+ */
+ _gtk_widget_set_anchored (widget, FALSE);
+ _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
+
toplevel_list = g_slist_prepend (toplevel_list, window);
}
else
{
_gtk_widget_set_is_toplevel (widget, FALSE);
toplevel_list = g_slist_remove (toplevel_list, window);
+
+ _gtk_widget_propagate_hierarchy_changed (widget, widget);
}
}
g_object_notify (G_OBJECT (window), "mnemonics-visible");
}
+ if (priv->auto_mnemonics_timeout_id)
+ {
+ g_source_remove (priv->auto_mnemonics_timeout_id);
+ priv->auto_mnemonics_timeout_id = 0;
+ }
+
priv->mnemonics_visible_set = TRUE;
}
+static gboolean
+set_auto_mnemonics_visible_cb (gpointer data)
+{
+ GtkWindow *window = data;
+
+ gtk_window_set_mnemonics_visible (window, TRUE);
+
+ window->priv->auto_mnemonics_timeout_id = 0;
+
+ return FALSE;
+}
+
+void
+_gtk_window_set_auto_mnemonics_visible (GtkWindow *window)
+{
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ if (window->priv->auto_mnemonics_timeout_id)
+ return;
+
+ window->priv->auto_mnemonics_timeout_id =
+ gdk_threads_add_timeout (AUTO_MNEMONICS_DELAY, set_auto_mnemonics_visible_cb, window);
+}
+
+/**
+ * gtk_window_get_focus_visible:
+ * @window: a #GtkWindow
+ *
+ * Gets the value of the #GtkWindow:focus-visible property.
+ *
+ * Returns: %TRUE if 'focus rectangles' are supposed to be visible
+ * in this window.
+ *
+ * Since: 3.2
+ */
+gboolean
+gtk_window_get_focus_visible (GtkWindow *window)
+{
+ g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+ return window->priv->focus_visible;
+}
+
+/**
+ * gtk_window_set_focus_visible:
+ * @window: a #GtkWindow
+ * @setting: the new value
+ *
+ * Sets the #GtkWindow:focus-visible property.
+ *
+ * Since: 3.2
+ */
+void
+gtk_window_set_focus_visible (GtkWindow *window,
+ gboolean setting)
+{
+ GtkWindowPrivate *priv;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ priv = window->priv;
+
+ setting = setting != FALSE;
+
+ if (priv->focus_visible != setting)
+ {
+ priv->focus_visible = setting;
+ g_object_notify (G_OBJECT (window), "focus-visible");
+ }
+}
+
void
_gtk_window_get_wmclass (GtkWindow *window,
gchar **wmclass_name,
*wmclass_name = priv->wmclass_name;
*wmclass_class = priv->wmclass_class;
}
+
+/**
+ * gtk_window_set_has_user_ref_count:
+ * @window: a #GtkWindow
+ * @setting: the new value
+ *
+ * Tells GTK+ whether to drop its extra reference to the window
+ * when gtk_widget_destroy() is called.
+ *
+ * This function is only exported for the benefit of language
+ * bindings which may need to keep the window alive until their
+ * wrapper object is garbage collected. There is no justification
+ * for ever calling this function in an application.
+ *
+ * Since: 3.0
+ */
+void
+gtk_window_set_has_user_ref_count (GtkWindow *window,
+ gboolean setting)
+{
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ window->priv->has_user_ref_count = setting;
+}
+
+static void
+ensure_state_flag_backdrop (GtkWidget *widget)
+{
+ GdkWindow *window;
+ gboolean window_focused = TRUE;
+
+ window = gtk_widget_get_window (widget);
+
+ window_focused = gdk_window_get_state (window) & GDK_WINDOW_STATE_FOCUSED;
+
+ if (!window_focused)
+ gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_BACKDROP, FALSE);
+ else
+ gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
+
+ gtk_widget_queue_draw (widget);
+}