Commit d9a6a829 authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Make it possible to track the embeddedness of statusicon (#387215, Martyn

2006-12-22  Matthias Clasen  <mclasen@redhat.com>

        Make it possible to track the embeddedness of
        statusicon (#387215, Martyn Russell, patch by Christian
        Persch)

        * gtk/gtkstatusicon.c: Add orientation and embedded properties.
        * gtk/gtkplug.c:
        * gtk/gtkplug-x11.c: Add an embedded property.
        * tests/teststatusicon.c: Test the new properties.
parent 33153bec
2006-12-22 Matthias Clasen <mclasen@redhat.com>
Make it possible to track the embeddedness of
statusicon (#387215, Martyn Russell, patch by Christian
Persch)
* gtk/gtkstatusicon.c: Add orientation and embedded properties.
* gtk/gtkplug.c:
* gtk/gtkplug-x11.c: Add an embedded property.
* tests/teststatusicon.c: Test the new properties.
* gtk/gtkwidget.c (gtk_widget_get_draw_rectangle): Don't
leak draw_border. (#387170, Kjartan Maraas)
......
......@@ -278,6 +278,8 @@ _gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent,
{
GTK_NOTE (PLUGSOCKET, g_message ("GtkPlug: calling gtk_plug_send_delete_event()\n"));
_gtk_plug_send_delete_event (widget);
g_object_notify (G_OBJECT (plug), "embedded");
}
}
else
......@@ -299,7 +301,7 @@ _gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent,
{
g_warning (G_STRLOC "Plug reparented unexpectedly into window in the same process");
plug->socket_window = NULL;
break;
break; /* FIXME: shouldn't this unref the plug? i.e. "goto done;" instead */
}
g_object_ref (plug->socket_window);
......@@ -308,13 +310,15 @@ _gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent,
{
plug->socket_window = gdk_window_foreign_new_for_display (display, xre->parent);
if (!plug->socket_window) /* Already gone */
break;
break; /* FIXME: shouldn't this unref the plug? i.e. "goto done;" instead */
}
_gtk_plug_add_all_grabbed_keys (plug);
if (!was_embedded)
g_signal_emit_by_name (plug, "embedded");
g_object_notify (G_OBJECT (plug), "embedded");
}
done:
......
......@@ -36,6 +36,10 @@
#include "gtkalias.h"
static void gtk_plug_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_plug_finalize (GObject *object);
static void gtk_plug_realize (GtkWidget *widget);
static void gtk_plug_unrealize (GtkWidget *widget);
......@@ -64,6 +68,11 @@ typedef struct
GdkModifierType accelerator_mods;
} GrabbedKey;
enum {
PROP_0,
PROP_EMBEDDED,
};
enum {
EMBEDDED,
LAST_SIGNAL
......@@ -73,6 +82,25 @@ static guint plug_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GtkPlug, gtk_plug, GTK_TYPE_WINDOW)
static void
gtk_plug_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkPlug *plug = GTK_PLUG (object);
switch (prop_id)
{
case PROP_EMBEDDED:
g_value_set_boolean (value, plug->socket_window != NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_plug_class_init (GtkPlugClass *class)
{
......@@ -83,6 +111,7 @@ gtk_plug_class_init (GtkPlugClass *class)
bin_class = g_type_class_peek (GTK_TYPE_BIN);
gobject_class->get_property = gtk_plug_get_property;
gobject_class->finalize = gtk_plug_finalize;
widget_class->realize = gtk_plug_realize;
......@@ -104,6 +133,21 @@ gtk_plug_class_init (GtkPlugClass *class)
window_class->set_focus = gtk_plug_set_focus;
window_class->keys_changed = gtk_plug_keys_changed;
/**
* GtkPlug:embedded:
*
* %TRUE if the plug is embedded in a socket.
*
* Since: 2.12
*/
g_object_class_install_property (gobject_class,
PROP_EMBEDDED,
g_param_spec_boolean ("embedded",
P_("Embedded"),
P_("Whether or not the plug is embedded"),
FALSE,
GTK_PARAM_READABLE));
plug_signals[EMBEDDED] =
g_signal_new (I_("embedded"),
G_OBJECT_CLASS_TYPE (class),
......
......@@ -69,6 +69,8 @@ enum
PROP_SIZE,
PROP_SCREEN,
PROP_VISIBLE,
PROP_ORIENTATION,
PROP_EMBEDDED,
PROP_BLINKING
};
......@@ -141,6 +143,9 @@ static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
GtkAllocation *allocation);
static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
GdkScreen *old_screen);
static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
#endif
static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
GdkEventButton *event);
......@@ -235,6 +240,39 @@ gtk_status_icon_class_init (GtkStatusIconClass *class)
GTK_PARAM_READWRITE));
/**
* GtkStatusIcon:embedded:
*
* %TRUE if the statusicon is embedded in a notification area.
*
* Since: 2.12
*/
g_object_class_install_property (gobject_class,
PROP_EMBEDDED,
g_param_spec_boolean ("embedded",
P_("Embedded"),
P_("Whether or not the status icon is embedded"),
FALSE,
GTK_PARAM_READABLE));
/**
* GtkStatusIcon:orientation:
*
* The orientation of the tray in which the statusicon
* is embedded.
*
* Since: 2.12
*/
g_object_class_install_property (gobject_class,
PROP_ORIENTATION,
g_param_spec_enum ("orientation",
P_("Orientation"),
P_("The orientation of the tray"),
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_HORIZONTAL,
GTK_PARAM_READABLE));
/**
* GtkStatusIcon::activate:
* @status_icon: the object which received the signal
......@@ -427,6 +465,10 @@ gtk_status_icon_init (GtkStatusIcon *status_icon)
gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
g_signal_connect_swapped (priv->tray_icon, "button-press-event",
G_CALLBACK (gtk_status_icon_button_press), status_icon);
g_signal_connect_swapped (priv->tray_icon, "screen-changed",
......@@ -623,6 +665,12 @@ gtk_status_icon_get_property (GObject *object,
case PROP_VISIBLE:
g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
break;
case PROP_EMBEDDED:
g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
break;
case PROP_ORIENTATION:
g_value_set_enum (value, _gtk_tray_icon_get_orientation (status_icon->priv->tray_icon));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -1076,6 +1124,18 @@ gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
#endif
static void
gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
{
g_object_notify (G_OBJECT (status_icon), "embedded");
}
static void
gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
{
g_object_notify (G_OBJECT (status_icon), "orientation");
}
static gboolean
gtk_status_icon_button_press (GtkStatusIcon *status_icon,
GdkEventButton *event)
......
......@@ -33,6 +33,29 @@ static TestStatus status = TEST_STATUS_INFO;
static gint timeout = 0;
static GSList *icons = NULL;
static void
size_changed_cb (GtkStatusIcon *icon,
int size)
{
g_print ("status icon %p size-changed size = %d\n", icon, size);
}
static void
embedded_changed_cb (GtkStatusIcon *icon)
{
g_print ("status icon %p embedded changed to %d\n", icon,
gtk_status_icon_is_embedded (icon));
}
static void
orientation_changed_cb (GtkStatusIcon *icon)
{
GtkOrientation orientation;
g_object_get (icon, "orientation", &orientation, NULL);
g_print ("status icon %p orientation changed to %d\n", icon, orientation);
}
static void
update_icons (void)
{
......@@ -264,7 +287,11 @@ main (int argc, char **argv)
gtk_status_icon_set_screen (icon, gdk_display_get_screen (display, i));
update_icons ();
gtk_status_icon_set_blinking (GTK_STATUS_ICON (icon), TRUE);
g_signal_connect (icon, "size-changed", G_CALLBACK (size_changed_cb), NULL);
g_signal_connect (icon, "notify::embedded", G_CALLBACK (embedded_changed_cb), NULL);
g_signal_connect (icon, "notify::orientation", G_CALLBACK (orientation_changed_cb), NULL);
g_print ("icon size %d\n", gtk_status_icon_get_size (icon));
gtk_status_icon_set_blinking (GTK_STATUS_ICON (icon), FALSE);
g_signal_connect (icon, "activate",
G_CALLBACK (icon_activated), NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment