[gtk+/rendering-cleanup: 107/140] window: Keep track of own visual
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/rendering-cleanup: 107/140] window: Keep track of own visual
- Date: Sun, 29 Aug 2010 16:12:27 +0000 (UTC)
commit d325cb52bdcdfe0e51e704f24e052f499ac9a473
Author: Benjamin Otte <otte redhat com>
Date: Sat Aug 28 19:49:03 2010 +0200
window: Keep track of own visual
Add gtk_window_set_visual() and a "visual" property. This allows
changing the window visual to the rgba one and other awesome things
(like implementing the trayicon spec).
docs/reference/gtk/gtk3-sections.txt | 1 +
gtk/gtk.symbols | 1 +
gtk/gtkwidget.c | 4 +-
gtk/gtkwindow.c | 119 +++++++++++++++++++++++++--------
gtk/gtkwindow.h | 4 +-
5 files changed, 97 insertions(+), 32 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 25486d7..6a670b5 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -4995,6 +4995,7 @@ gtk_window_get_gravity
gtk_window_set_position
gtk_window_set_transient_for
gtk_window_set_destroy_with_parent
+gtk_window_set_visual
gtk_window_set_screen
gtk_window_get_screen
gtk_window_is_active
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 4ef08d5..242396e 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -4615,6 +4615,7 @@ gtk_window_set_urgency_hint
gtk_window_set_title
gtk_window_set_transient_for
gtk_window_set_type_hint
+gtk_window_set_visual
gtk_window_set_wmclass
gtk_window_stick
gtk_window_unfullscreen
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 6e7e51e..6097750 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -7495,7 +7495,7 @@ gtk_widget_get_screen_unchecked (GtkWidget *widget)
if (gtk_widget_is_toplevel (toplevel))
{
if (GTK_IS_WINDOW (toplevel))
- return GTK_WINDOW (toplevel)->screen;
+ return gtk_window_get_screen (GTK_WINDOW (toplevel));
else if (GTK_IS_INVISIBLE (toplevel))
return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
}
@@ -8219,7 +8219,7 @@ gtk_widget_get_visual (GtkWidget *widget)
return gdk_drawable_get_visual (widget->window);
if (GTK_IS_WINDOW (w))
- return gdk_screen_get_system_visual (GTK_WINDOW (w)->screen);
+ return GTK_WINDOW (w)->visual;
}
return gdk_screen_get_system_visual (gdk_screen_get_default ());
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index f736252..2b9ddf8 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -113,6 +113,7 @@ enum {
PROP_ICON,
PROP_ICON_NAME,
PROP_SCREEN,
+ PROP_VISUAL,
PROP_TYPE_HINT,
PROP_SKIP_TASKBAR_HINT,
PROP_SKIP_PAGER_HINT,
@@ -660,6 +661,20 @@ gtk_window_class_init (GtkWindowClass *klass)
GDK_TYPE_SCREEN,
GTK_PARAM_READWRITE));
+ /**
+ * GtkWindow:visual:
+ *
+ * Specifies the visual used to create the window with. See gtk_window_set_visual()
+ * for more details.
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_VISUAL,
+ g_param_spec_object ("visual",
+ P_("Visual"),
+ P_("The visual this window is created from"),
+ GDK_TYPE_VISUAL,
+ GTK_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class,
PROP_IS_ACTIVE,
g_param_spec_boolean ("is-active",
@@ -963,7 +978,7 @@ gtk_window_init (GtkWindow *window)
window->gravity = GDK_GRAVITY_NORTH_WEST;
window->decorated = TRUE;
window->mnemonic_modifier = GDK_MOD1_MASK;
- window->screen = gdk_screen_get_default ();
+ window->visual = gdk_screen_get_system_visual (gdk_screen_get_default ());
priv->accept_focus = TRUE;
priv->focus_on_map = TRUE;
@@ -979,7 +994,7 @@ gtk_window_init (GtkWindow *window)
gtk_decorated_window_init (window);
- g_signal_connect (window->screen, "composited-changed",
+ g_signal_connect (gdk_screen_get_default (), "composited-changed",
G_CALLBACK (gtk_window_on_composited_changed), window);
}
@@ -1043,6 +1058,9 @@ gtk_window_set_property (GObject *object,
case PROP_SCREEN:
gtk_window_set_screen (window, g_value_get_object (value));
break;
+ case PROP_VISUAL:
+ gtk_window_set_visual (window, g_value_get_object (value));
+ break;
case PROP_TYPE_HINT:
gtk_window_set_type_hint (window,
g_value_get_enum (value));
@@ -1148,7 +1166,10 @@ gtk_window_get_property (GObject *object,
g_value_set_string (value, gtk_window_get_icon_name (window));
break;
case PROP_SCREEN:
- g_value_set_object (value, window->screen);
+ g_value_set_object (value, gdk_visual_get_screen (window->visual));
+ break;
+ case PROP_VISUAL:
+ g_value_set_object (value, window->visual);
break;
case PROP_IS_ACTIVE:
g_value_set_boolean (value, window->is_active);
@@ -2209,7 +2230,7 @@ gtk_window_transient_parent_screen_changed (GtkWindow *parent,
GParamSpec *pspec,
GtkWindow *window)
{
- gtk_window_set_screen (window, parent->screen);
+ gtk_window_set_screen (window, gtk_window_get_screen (parent));
}
static void
@@ -2304,7 +2325,7 @@ gtk_window_set_transient_for (GtkWindow *window,
G_CALLBACK (gtk_window_transient_parent_screen_changed),
window);
- gtk_window_set_screen (window, parent->screen);
+ gtk_window_set_screen (window, gtk_window_get_screen (parent));
if (window->destroy_with_parent)
connect_parent_destroyed (window);
@@ -4259,8 +4280,8 @@ gtk_window_finalize (GObject *object)
window->keys_changed_handler = 0;
}
- if (window->screen)
- g_signal_handlers_disconnect_by_func (window->screen,
+ if (window->visual)
+ g_signal_handlers_disconnect_by_func (gdk_visual_get_screen (window->visual),
gtk_window_on_composited_changed, window);
g_free (priv->startup_id);
@@ -7315,45 +7336,51 @@ gtk_window_begin_move_drag (GtkWindow *window,
timestamp);
}
-/**
- * gtk_window_set_screen:
- * @window: a #GtkWindow.
- * @screen: a #GdkScreen.
+/**
+ * gtk_window_set_visual:
+ * @window: window to set the visual from
+ * @visual: the new visual to use
*
- * Sets the #GdkScreen where the @window is displayed; if
- * the window is already mapped, it will be unmapped, and
- * then remapped on the new screen.
+ * Sets the #GdkVisual used to display @window; if the window
+ * is already mapped, it will be unmapped, and then remapped
+ * with the new visual. It is fine if @visual is on a
+ * different #GdkScreen.
*
- * Since: 2.2
- */
+ * By default, a window's visual is set to the system visual
+ * of the default screen.
+ **/
void
-gtk_window_set_screen (GtkWindow *window,
- GdkScreen *screen)
+gtk_window_set_visual (GtkWindow *window,
+ GdkVisual *visual)
{
GtkWidget *widget;
- GdkScreen *previous_screen;
+ GdkVisual *previous_visual;
+ GdkScreen *previous_screen, *screen;
gboolean was_mapped;
g_return_if_fail (GTK_IS_WINDOW (window));
- g_return_if_fail (GDK_IS_SCREEN (screen));
+ g_return_if_fail (GDK_IS_VISUAL (visual));
- if (screen == window->screen)
+ if (window->visual == visual)
return;
widget = GTK_WIDGET (window);
- previous_screen = window->screen;
+ previous_visual = window->visual;
+ previous_screen = gdk_visual_get_screen (previous_visual);
+ screen = gdk_visual_get_screen (visual);
was_mapped = gtk_widget_get_mapped (widget);
if (was_mapped)
gtk_widget_unmap (widget);
if (gtk_widget_get_realized (widget))
gtk_widget_unrealize (widget);
-
+ g_object_freeze_notify (G_OBJECT (window));
+
gtk_window_free_key_hash (window);
- window->screen = screen;
+ window->visual = visual;
gtk_widget_reset_rc_styles (widget);
- if (screen != previous_screen)
+ if (previous_screen != screen)
{
g_signal_handlers_disconnect_by_func (previous_screen,
gtk_window_on_composited_changed, window);
@@ -7362,13 +7389,47 @@ gtk_window_set_screen (GtkWindow *window,
_gtk_widget_propagate_screen_changed (widget, previous_screen);
_gtk_widget_propagate_composited_changed (widget);
+ g_object_notify (G_OBJECT (window), "screen");
}
- g_object_notify (G_OBJECT (window), "screen");
+ g_object_notify (G_OBJECT (window), "visual");
+ g_object_thaw_notify (G_OBJECT (window));
if (was_mapped)
gtk_widget_map (widget);
}
+/**
+ * gtk_window_set_screen:
+ * @window: a #GtkWindow.
+ * @screen: a #GdkScreen.
+ *
+ * Sets the #GdkScreen where the @window is displayed. If
+ * the @screen is equal to @window's current screen, this
+ * function does nothing. If it is not and the window is
+ * already mapped, it will be unmapped, and then remapped
+ * on the new screen.
+ *
+ * This function resets @window's visual to the system
+ * visual of the given @screen. If you want to use a
+ * different visual, consider using gtk_window_set_visual()
+ * instead.
+ *
+ * Since: 2.2
+ */
+void
+gtk_window_set_screen (GtkWindow *window,
+ GdkScreen *screen)
+{
+ g_return_if_fail (GTK_IS_WINDOW (window));
+ g_return_if_fail (GDK_IS_SCREEN (screen));
+
+ if (screen == gdk_visual_get_screen (window->visual))
+ return;
+
+ gtk_window_set_visual (window,
+ gdk_screen_get_system_visual (screen));
+}
+
static void
gtk_window_on_composited_changed (GdkScreen *screen,
GtkWindow *window)
@@ -7381,8 +7442,8 @@ gtk_window_on_composited_changed (GdkScreen *screen,
static GdkScreen *
gtk_window_check_screen (GtkWindow *window)
{
- if (window->screen)
- return window->screen;
+ if (window->visual)
+ return gdk_visual_get_screen (window->visual);
else
{
g_warning ("Screen for GtkWindow not set; you must always set\n"
@@ -7406,7 +7467,7 @@ gtk_window_get_screen (GtkWindow *window)
{
g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
- return window->screen;
+ return gdk_visual_get_screen (window->visual);
}
/**
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 0a95b18..20003d1 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -113,7 +113,7 @@ struct _GtkWindow
guint GSEAL (keys_changed_handler);
GdkModifierType GSEAL (mnemonic_modifier);
- GdkScreen *GSEAL (screen);
+ GdkVisual *GSEAL (visual);
};
struct _GtkWindowClass
@@ -253,6 +253,8 @@ void gtk_window_set_geometry_hints (GtkWindow *window,
void gtk_window_set_screen (GtkWindow *window,
GdkScreen *screen);
GdkScreen* gtk_window_get_screen (GtkWindow *window);
+void gtk_window_set_visual (GtkWindow *window,
+ GdkVisual *visual);
gboolean gtk_window_is_active (GtkWindow *window);
gboolean gtk_window_has_toplevel_focus (GtkWindow *window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]