Commit a7dae10a authored by Sean Davis's avatar Sean Davis 🕶

Make the arrow work with statusnotifiers

parent 3ab175f6
Pipeline #1131 passed with stages
in 4 minutes and 13 seconds
......@@ -34,6 +34,10 @@
static void sn_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void sn_box_finalize (GObject *object);
static void sn_box_collect_known_items (SnBox *box,
......@@ -68,6 +72,12 @@ static void sn_box_size_allocate (GtkWidget
enum
{
PROP_0,
PROP_HAS_HIDDEN
};
struct _SnBoxClass
{
GtkContainerClass __parent__;
......@@ -81,6 +91,11 @@ struct _SnBox
/* in theory it's possible to have multiple items with same name */
GHashTable *children;
/* hidden children counter */
gint n_hidden_children;
gint n_visible_children;
gboolean show_hidden;
};
G_DEFINE_TYPE (SnBox, sn_box, GTK_TYPE_CONTAINER)
......@@ -95,6 +110,7 @@ sn_box_class_init (SnBoxClass *klass)
GtkContainerClass *container_class;
object_class = G_OBJECT_CLASS (klass);
object_class->get_property = sn_box_get_property;
object_class->finalize = sn_box_finalize;
widget_class = GTK_WIDGET_CLASS (klass);
......@@ -107,6 +123,13 @@ sn_box_class_init (SnBoxClass *klass)
container_class->remove = sn_box_remove;
container_class->forall = sn_box_forall;
container_class->child_type = sn_box_child_type;
g_object_class_install_property (object_class,
PROP_HAS_HIDDEN,
g_param_spec_boolean ("has-hidden",
NULL, NULL,
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
......@@ -123,6 +146,28 @@ sn_box_init (SnBox *box)
static void
sn_box_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SnBox *box = XFCE_SN_BOX(object);
switch (prop_id)
{
case PROP_HAS_HIDDEN:
g_value_set_boolean(value, box->n_hidden_children > 0);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
sn_box_finalize (GObject *object)
{
......@@ -182,12 +227,11 @@ sn_box_list_changed (SnBox *box,
{
SnButton *button;
GList *known_items, *li, *li_int, *li_tmp;
gint n_hidden_children = 0, n_visible_children = 0;
g_return_if_fail (XFCE_IS_SN_BOX (box));
g_return_if_fail (XFCE_IS_SN_CONFIG (config));
gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback)gtk_widget_unmap, NULL);
known_items = sn_config_get_known_items (box->config);
for (li = known_items; li != NULL; li = li->next)
{
......@@ -198,10 +242,23 @@ sn_box_list_changed (SnBox *box,
if (!sn_config_is_hidden (box->config,
sn_button_get_name (button)))
{
gtk_widget_map (GTK_WIDGET (button));
gtk_widget_map (GTK_WIDGET(button));
n_visible_children++;
}
else
{
gtk_widget_set_mapped (GTK_WIDGET (button), box->show_hidden);
n_hidden_children++;
}
}
}
box->n_visible_children = n_visible_children;
if (box->n_hidden_children != n_hidden_children)
{
box->n_hidden_children = n_hidden_children;
g_object_notify (G_OBJECT (box), "has-hidden");
}
gtk_widget_queue_resize (GTK_WIDGET (box));
}
......@@ -311,6 +368,8 @@ sn_box_measure_and_allocate (GtkWidget *widget,
GtkRequisition child_req;
GtkAllocation child_alloc;
gint n_hidden_children = 0, n_visible_children = 0;
panel_size = sn_config_get_panel_size (box->config);
config_nrows = sn_config_get_nrows (box->config);
icon_size = sn_config_get_icon_size (box->config);
......@@ -344,8 +403,15 @@ sn_box_measure_and_allocate (GtkWidget *widget,
if (sn_config_is_hidden (box->config,
sn_button_get_name (button)))
{
continue;
n_hidden_children++;
if (!box->show_hidden)
{
gtk_widget_unmap (GTK_WIDGET (button));
continue;
}
}
gtk_widget_map (GTK_WIDGET (button));
n_visible_children++;
gtk_widget_get_preferred_size (GTK_WIDGET (button), NULL, &child_req);
......@@ -415,6 +481,13 @@ sn_box_measure_and_allocate (GtkWidget *widget,
if (natural_length != NULL)
*natural_length = total_length;
box->n_visible_children = n_visible_children;
if (box->n_hidden_children != n_hidden_children)
{
box->n_hidden_children = n_hidden_children;
g_object_notify(G_OBJECT(box), "has-hidden");
}
}
......@@ -509,3 +582,25 @@ sn_box_remove_item (SnBox *box,
}
}
}
gboolean
sn_box_has_hidden_items (SnBox *box)
{
g_return_val_if_fail (XFCE_IS_SN_BOX (box), FALSE);
return box->n_hidden_children > 0;
}
void
sn_box_set_show_hidden (SnBox *box,
gboolean show_hidden)
{
g_return_if_fail (XFCE_IS_SN_BOX (box));
if (box->show_hidden != show_hidden)
{
box->show_hidden = show_hidden;
if (box->children != NULL)
gtk_widget_queue_resize (GTK_WIDGET (box));
}
}
\ No newline at end of file
......@@ -43,7 +43,10 @@ void sn_box_remove_item (SnBox
SnItem *item);
GtkWidget *sn_box_new (SnConfig *config);
gboolean sn_box_has_hidden_items (SnBox *box);
void sn_box_set_show_hidden (SnBox *box,
gboolean show_hidden);
G_END_DECLS
G_END_DECLS
#endif /* !__SN_BOX_H__ */
......@@ -226,6 +226,72 @@ sn_plugin_item_removed (SnPlugin *plugin,
}
static void
update_button_visibility (SnPlugin *plugin)
{
gboolean visible = plugin->has_hidden_systray_items || plugin->has_hidden_sn_items;
gtk_widget_set_visible(GTK_WIDGET(plugin->button), visible);
}
static void
systray_has_hidden_cb (SystrayBox *box,
GParamSpec *pspec,
SnPlugin *plugin)
{
plugin->has_hidden_systray_items = systray_box_has_hidden_items (box);
update_button_visibility (plugin);
}
static void
snbox_has_hidden_cb (SnBox *box,
GParamSpec *pspec,
SnPlugin *plugin)
{
plugin->has_hidden_sn_items = sn_box_has_hidden_items (box);
update_button_visibility (plugin);
}
static void
sn_plugin_button_set_arrow(SnPlugin *plugin)
{
GtkArrowType arrow_type;
gboolean show_hidden;
GtkOrientation orientation;
panel_return_if_fail(XFCE_IS_SN_PLUGIN(plugin));
show_hidden = systray_box_get_show_hidden(XFCE_SYSTRAY_BOX(plugin->systray_box));
orientation = xfce_panel_plugin_get_orientation(XFCE_PANEL_PLUGIN(plugin));
if (orientation == GTK_ORIENTATION_HORIZONTAL)
arrow_type = show_hidden ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT;
else
arrow_type = show_hidden ? GTK_ARROW_UP : GTK_ARROW_DOWN;
xfce_arrow_button_set_arrow_type(XFCE_ARROW_BUTTON(plugin->button), arrow_type);
}
void
sn_plugin_button_toggled (GtkWidget *button,
SnPlugin *plugin)
{
panel_return_if_fail (XFCE_IS_SN_PLUGIN (plugin));
panel_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
panel_return_if_fail (plugin->button == button);
systray_box_set_show_hidden (XFCE_SYSTRAY_BOX (plugin->systray_box),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
sn_box_set_show_hidden (XFCE_SN_BOX (plugin->sn_box),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
sn_plugin_button_set_arrow (plugin);
}
static void
sn_plugin_construct (XfcePanelPlugin *panel_plugin)
......@@ -286,10 +352,11 @@ sn_plugin_construct (XfcePanelPlugin *panel_plugin)
plugin->button = xfce_arrow_button_new(GTK_ARROW_RIGHT);
gtk_box_pack_start(GTK_BOX(plugin->box), plugin->button, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(plugin->button), "toggled",
G_CALLBACK(systray_plugin_button_toggled), plugin);
G_CALLBACK(sn_plugin_button_toggled), plugin);
gtk_button_set_relief(GTK_BUTTON(plugin->button), GTK_RELIEF_NONE);
g_object_bind_property(G_OBJECT(plugin->systray_box), "has-hidden",
G_OBJECT(plugin->button), "visible",
G_BINDING_SYNC_CREATE);
g_signal_connect (G_OBJECT(plugin->systray_box), "notify::has-hidden",
G_CALLBACK(systray_has_hidden_cb), plugin);
g_signal_connect (G_OBJECT(plugin->sn_box), "notify::has-hidden",
G_CALLBACK(snbox_has_hidden_cb), plugin);
xfce_panel_plugin_add_action_widget(XFCE_PANEL_PLUGIN(plugin), plugin->button);
}
......@@ -53,6 +53,8 @@ struct _SnPlugin
SystrayManager *manager;
guint idle_startup;
gboolean has_hidden_systray_items;
gboolean has_hidden_sn_items;
/* Widgets */
GtkWidget *box;
......
......@@ -940,3 +940,12 @@ systray_box_update (SystrayBox *box,
/* update the box, so we update the has-hidden property */
gtk_widget_queue_resize (GTK_WIDGET (box));
}
gboolean
systray_box_has_hidden_items (SystrayBox *box)
{
g_return_val_if_fail (XFCE_IS_SYSTRAY_BOX (box), FALSE);
return box->n_hidden_children > 0;
}
......@@ -65,4 +65,6 @@ gboolean systray_box_get_squared (SystrayBox *box);
void systray_box_update (SystrayBox *box,
GSList *names_ordered);
gboolean systray_box_has_hidden_items (SystrayBox *box);
#endif /* !__SYSTRAY_BOX_H__ */
......@@ -40,7 +40,6 @@
#define BUTTON_SIZE (16)
static void systray_plugin_button_set_arrow (SnPlugin *plugin);
static void systray_plugin_names_update (SnPlugin *plugin);
static gboolean systray_plugin_names_get_hidden (SnPlugin *plugin,
const gchar *name);
......@@ -224,8 +223,6 @@ systray_plugin_orientation_changed (XfcePanelPlugin *panel_plugin,
gtk_widget_set_size_request (plugin->button, BUTTON_SIZE, -1);
else
gtk_widget_set_size_request (plugin->button, -1, BUTTON_SIZE);
systray_plugin_button_set_arrow (plugin);
}
......@@ -296,42 +293,6 @@ systray_plugin_box_draw (GtkWidget *box,
void
systray_plugin_button_toggled (GtkWidget *button,
SnPlugin *plugin)
{
panel_return_if_fail (XFCE_IS_SN_PLUGIN (plugin));
panel_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
panel_return_if_fail (plugin->button == button);
systray_box_set_show_hidden (XFCE_SYSTRAY_BOX (plugin->systray_box),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
systray_plugin_button_set_arrow (plugin);
}
static void
systray_plugin_button_set_arrow (SnPlugin *plugin)
{
GtkArrowType arrow_type;
gboolean show_hidden;
GtkOrientation orientation;
panel_return_if_fail (XFCE_IS_SN_PLUGIN (plugin));
show_hidden = systray_box_get_show_hidden (XFCE_SYSTRAY_BOX (plugin->systray_box));
orientation = xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin));
if (orientation == GTK_ORIENTATION_HORIZONTAL)
arrow_type = show_hidden ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT;
else
arrow_type = show_hidden ? GTK_ARROW_UP : GTK_ARROW_DOWN;
xfce_arrow_button_set_arrow_type (XFCE_ARROW_BUTTON (plugin->button), arrow_type);
}
static void
systray_plugin_names_update_icon (GtkWidget *icon,
gpointer data)
......
......@@ -36,8 +36,6 @@ GType systray_plugin_get_type (void) G_GNUC_CONST;
void systray_plugin_box_draw (GtkWidget *box,
cairo_t *cr,
gpointer user_data);
void systray_plugin_button_toggled (GtkWidget *button,
SnPlugin *plugin);
void systray_plugin_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen);
void systray_plugin_composited_changed (GtkWidget *widget);
......
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