From 5027993097729e980239ac1ed65e86bd31d2901d Mon Sep 17 00:00:00 2001 From: Fabien Broquard Date: Tue, 2 Oct 2018 20:16:53 +0200 Subject: na-tray: wide panels, preliminary batch box to grid rename box/Box/BOX changed to grid/Grid/GRID as a preliminary step to prepare for changing GtkBox in na-box/na-grid to a GtkGrid to make the notification area work well on vertical and wide panels note: even if everything is renamed to grid, the GtkWidget is still a GtkBox thats why GtkBox and GTK_TYPE_BOX have not been renamed. --- applets/notification_area/Makefile.am | 4 +- applets/notification_area/main.c | 26 +-- applets/notification_area/na-box.c | 371 ---------------------------------- applets/notification_area/na-box.h | 56 ----- applets/notification_area/na-grid.c | 371 ++++++++++++++++++++++++++++++++++ applets/notification_area/na-grid.h | 43 ++++ applets/notification_area/testtray.c | 4 +- 7 files changed, 431 insertions(+), 444 deletions(-) delete mode 100644 applets/notification_area/na-box.c delete mode 100644 applets/notification_area/na-box.h create mode 100644 applets/notification_area/na-grid.c create mode 100644 applets/notification_area/na-grid.h (limited to 'applets') diff --git a/applets/notification_area/Makefile.am b/applets/notification_area/Makefile.am index 083b4524..b584f084 100644 --- a/applets/notification_area/Makefile.am +++ b/applets/notification_area/Makefile.am @@ -20,8 +20,8 @@ AM_CPPFLAGS = \ AM_CFLAGS = $(WARN_CFLAGS) libtray_la_SOURCES = \ - na-box.c \ - na-box.h \ + na-grid.c \ + na-grid.h \ na-host.c \ na-host.h \ na-item.c \ diff --git a/applets/notification_area/main.c b/applets/notification_area/main.c index f656d029..df07a3e2 100644 --- a/applets/notification_area/main.c +++ b/applets/notification_area/main.c @@ -30,7 +30,7 @@ #include #include "main.h" -#include "na-box.h" +#include "na-grid.h" #ifdef PROVIDE_WATCHER_SERVICE # include "libstatus-notifier-watcher/gf-status-notifier-watcher.h" @@ -40,7 +40,7 @@ struct _NaTrayAppletPrivate { - GtkWidget *box; + GtkWidget *grid; #ifdef PROVIDE_WATCHER_SERVICE GfStatusNotifierWatcher *sn_watcher; @@ -225,14 +225,14 @@ na_tray_applet_style_updated (GtkWidget *widget) if (parent_class_style_updated) parent_class_style_updated (widget); - if (!applet->priv->box) + if (!applet->priv->grid) return; gtk_widget_style_get (widget, "icon-padding", &padding, "icon-size", &icon_size, NULL); - g_object_set (applet->priv->box, + g_object_set (applet->priv->grid, "icon-padding", padding, "icon-size", icon_size, NULL); @@ -247,8 +247,8 @@ na_tray_applet_change_background(MatePanelApplet* panel_applet, MatePanelAppletB parent_class_change_background (panel_applet, type, color, pattern); } - if (applet->priv->box) - na_box_force_redraw (NA_BOX (applet->priv->box)); + if (applet->priv->grid) + na_grid_force_redraw (NA_GRID (applet->priv->grid)); } static void @@ -260,10 +260,10 @@ na_tray_applet_change_orient (MatePanelApplet *panel_applet, if (parent_class_change_orient) parent_class_change_orient (panel_applet, orient); - if (!applet->priv->box) + if (!applet->priv->grid) return; - gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->priv->box), + gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->priv->grid), get_gtk_orientation_from_applet_orient (orient)); } @@ -286,10 +286,10 @@ na_tray_applet_focus (GtkWidget *widget, { NaTrayApplet *applet = NA_TRAY_APPLET (widget); - /* We let the box handle the focus movement because we behave more like a + /* We let the grid handle the focus movement because we behave more like a * container than a single applet. But if focus didn't move, we let the * applet do its thing. */ - if (gtk_widget_child_focus (applet->priv->box, direction)) + if (gtk_widget_child_focus (applet->priv->grid, direction)) return TRUE; return GTK_WIDGET_CLASS (na_tray_applet_parent_class)->focus (widget, direction); @@ -353,10 +353,10 @@ na_tray_applet_init (NaTrayApplet *applet) #endif orient = mate_panel_applet_get_orient (MATE_PANEL_APPLET (applet)); - applet->priv->box = na_box_new (get_gtk_orientation_from_applet_orient (orient)); + applet->priv->grid = na_grid_new (get_gtk_orientation_from_applet_orient (orient)); - gtk_container_add (GTK_CONTAINER (applet), GTK_WIDGET (applet->priv->box)); - gtk_widget_show (GTK_WIDGET (applet->priv->box)); + gtk_container_add (GTK_CONTAINER (applet), GTK_WIDGET (applet->priv->grid)); + gtk_widget_show (GTK_WIDGET (applet->priv->grid)); atko = gtk_widget_get_accessible (GTK_WIDGET (applet)); atk_object_set_name (atko, _("Panel Notification Area")); diff --git a/applets/notification_area/na-box.c b/applets/notification_area/na-box.c deleted file mode 100644 index db9a26e4..00000000 --- a/applets/notification_area/na-box.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (C) 2002 Red Hat, Inc. - * Copyright (C) 2003-2006 Vincent Untz - * Copyright (C) 2007 Christian Persch - * Copyright (C) 2017 Colomban Wendling - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -/* Well, actuall'y is the Tray itself, the container for the items. But - * NaTray is already taken for the XEMBED part, so for now it's called NaBox, - * don't make a big deal out of it. */ - -#include "config.h" - -#include - -#include "na-box.h" - -#include "system-tray/na-tray.h" -#include "status-notifier/sn-host-v0.h" - -#define ICON_SPACING 1 -#define MIN_BOX_SIZE 3 - -struct _NaBox -{ - GtkBox parent; - - gint icon_padding; - gint icon_size; - - GSList *hosts; - GSList *items; -}; - -enum -{ - PROP_0, - PROP_ICON_PADDING, - PROP_ICON_SIZE -}; - -G_DEFINE_TYPE (NaBox, na_box, GTK_TYPE_BOX) - -static gint -compare_items (gconstpointer a, - gconstpointer b) -{ - NaItem *item1; - NaItem *item2; - NaItemCategory c1; - NaItemCategory c2; - const gchar *id1; - const gchar *id2; - - item1 = (NaItem *) a; - item2 = (NaItem *) b; - - c1 = na_item_get_category (item1); - c2 = na_item_get_category (item2); - - if (c1 < c2) - return -1; - else if (c1 > c2) - return 1; - - id1 = na_item_get_id (item1); - id2 = na_item_get_id (item2); - - return g_strcmp0 (id1, id2); -} - -static void -reorder_items (GtkWidget *widget, - gpointer user_data) -{ - NaBox *nb; - gint position; - - nb = NA_BOX (user_data); - - position = g_slist_index (nb->items, widget); - gtk_box_reorder_child (GTK_BOX (nb), widget, position); -} - -static void -item_added_cb (NaHost *host, - NaItem *item, - NaBox *self) -{ - g_return_if_fail (NA_IS_HOST (host)); - g_return_if_fail (NA_IS_ITEM (item)); - g_return_if_fail (NA_IS_BOX (self)); - - g_object_bind_property (self, "orientation", - item, "orientation", - G_BINDING_SYNC_CREATE); - - self->items = g_slist_prepend (self->items, item); - gtk_box_pack_start (GTK_BOX (self), GTK_WIDGET (item), FALSE, FALSE, 0); - - self->items = g_slist_sort (self->items, compare_items); - gtk_container_foreach (GTK_CONTAINER (self), reorder_items, self); -} - -static void -item_removed_cb (NaHost *host, - NaItem *item, - NaBox *self) -{ - g_return_if_fail (NA_IS_HOST (host)); - g_return_if_fail (NA_IS_ITEM (item)); - g_return_if_fail (NA_IS_BOX (self)); - - gtk_container_remove (GTK_CONTAINER (self), GTK_WIDGET (item)); - self->items = g_slist_remove (self->items, item); -} - -static void -update_size_and_orientation (NaBox *self, - GtkOrientation orientation) -{ - /* FIXME: do we really need that? comes from NaTray */ - /* FIXME: if we do, do that in overridden preferred size handlers */ - - /* note, you want this larger if the frame has non-NONE relief by default. */ - switch (orientation) - { - case GTK_ORIENTATION_VERTICAL: - /* Give box a min size so the frame doesn't look dumb */ - gtk_widget_set_size_request (GTK_WIDGET (self), MIN_BOX_SIZE, -1); - break; - case GTK_ORIENTATION_HORIZONTAL: - gtk_widget_set_size_request (GTK_WIDGET (self), -1, MIN_BOX_SIZE); - break; - } -} - -static void -orientation_notify (GObject *object, - GParamSpec *pspec, - gpointer data) -{ - update_size_and_orientation (NA_BOX (object), - gtk_orientable_get_orientation (GTK_ORIENTABLE (object))); -} - -static void -na_box_init (NaBox *self) -{ - GtkOrientation orientation; - - self->icon_padding = 0; - self->icon_size = 0; - - self->hosts = NULL; - self->items = NULL; - - orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (self)); - update_size_and_orientation (self, orientation); - - g_signal_connect (self, "notify::orientation", G_CALLBACK (orientation_notify), NULL); -} - -static void -add_host (NaBox *self, - NaHost *host) -{ - self->hosts = g_slist_prepend (self->hosts, host); - - g_object_bind_property (self, "icon-padding", host, "icon-padding", - G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); - g_object_bind_property (self, "icon-size", host, "icon-size", - G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); - - g_signal_connect_object (host, "item-added", - G_CALLBACK (item_added_cb), self, 0); - g_signal_connect_object (host, "item-removed", - G_CALLBACK (item_removed_cb), self, 0); -} - -static void -na_box_style_updated (GtkWidget *widget) -{ - NaBox *self = NA_BOX (widget); - GtkStyleContext *context; - GSList *node; - - if (GTK_WIDGET_CLASS (na_box_parent_class)->style_updated) - GTK_WIDGET_CLASS (na_box_parent_class)->style_updated (widget); - - context = gtk_widget_get_style_context (widget); - - for (node = self->hosts; node; node = node->next) - { - gtk_style_context_save (context); - na_host_style_updated (node->data, context); - gtk_style_context_restore (context); - } -} - -/* Custom drawing because system-tray items need weird stuff. */ -static gboolean -na_box_draw (GtkWidget *box, - cairo_t *cr) -{ - GList *child; - GList *children = gtk_container_get_children (GTK_CONTAINER (box)); - - for (child = children; child; child = child->next) - { - if (! NA_IS_ITEM (child->data) || - ! na_item_draw_on_parent (child->data, box, cr)) - { - if (gtk_widget_is_drawable (child->data) && - gtk_cairo_should_draw_window (cr, gtk_widget_get_window (child->data))) - gtk_container_propagate_draw (GTK_CONTAINER (box), child->data, cr); - } - } - - g_list_free (children); - - return TRUE; -} - -static void -na_box_realize (GtkWidget *widget) -{ - NaBox *self = NA_BOX (widget); - GdkScreen *screen; - GtkOrientation orientation; - NaHost *tray_host; - - GTK_WIDGET_CLASS (na_box_parent_class)->realize (widget); - - /* Instantiate the hosts now we have a screen */ - screen = gtk_widget_get_screen (GTK_WIDGET (self)); - orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (self)); - tray_host = na_tray_new_for_screen (screen, orientation); - g_object_bind_property (self, "orientation", - tray_host, "orientation", - G_BINDING_DEFAULT); - - add_host (self, tray_host); - add_host (self, sn_host_v0_new ()); -} - -static void -na_box_unrealize (GtkWidget *widget) -{ - NaBox *self = NA_BOX (widget); - - if (self->hosts != NULL) - { - g_slist_free_full (self->hosts, g_object_unref); - self->hosts = NULL; - } - - g_clear_pointer (&self->items, g_slist_free); - - GTK_WIDGET_CLASS (na_box_parent_class)->unrealize (widget); -} - -static void -na_box_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - NaBox *self = NA_BOX (object); - - switch (property_id) - { - case PROP_ICON_PADDING: - g_value_set_int (value, self->icon_padding); - break; - - case PROP_ICON_SIZE: - g_value_set_int (value, self->icon_size); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -na_box_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - NaBox *self = NA_BOX (object); - - switch (property_id) - { - case PROP_ICON_PADDING: - self->icon_padding = g_value_get_int (value); - break; - - case PROP_ICON_SIZE: - self->icon_size = g_value_get_int (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -na_box_class_init (NaBoxClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - gobject_class->get_property = na_box_get_property; - gobject_class->set_property = na_box_set_property; - - widget_class->draw = na_box_draw; - widget_class->realize = na_box_realize; - widget_class->unrealize = na_box_unrealize; - widget_class->style_updated = na_box_style_updated; - - g_object_class_install_property (gobject_class, PROP_ICON_PADDING, - g_param_spec_int ("icon-padding", - "Padding around icons", - "Padding that should be put around icons, in pixels", - 0, G_MAXINT, 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (gobject_class, PROP_ICON_SIZE, - g_param_spec_int ("icon-size", - "Icon size", - "If non-zero, hardcodes the size of the icons in pixels", - 0, G_MAXINT, 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); -} - -GtkWidget * -na_box_new (GtkOrientation orientation) -{ - return g_object_new (NA_TYPE_BOX, - "orientation", orientation, - "spacing", ICON_SPACING, - NULL); -} - -void -na_box_force_redraw (NaBox *box) -{ - GSList *node; - - for (node = box->hosts; node; node = node->next) - na_host_force_redraw (node->data); -} diff --git a/applets/notification_area/na-box.h b/applets/notification_area/na-box.h deleted file mode 100644 index 5e13b488..00000000 --- a/applets/notification_area/na-box.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* na-tray-tray.h - * Copyright (C) 2002 Anders Carlsson - * Copyright (C) 2003-2006 Vincent Untz - * Copyright (C) 2017 Colomban Wendling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * 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., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Used to be: eggtraytray.h - */ - -#ifndef NA_BOX_H -#define NA_BOX_H - -#ifdef GDK_WINDOWING_X11 -#include -#endif -#include - -G_BEGIN_DECLS - -#define NA_TYPE_BOX (na_box_get_type ()) -#define NA_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NA_TYPE_BOX, NaBox)) -#define NA_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NA_TYPE_BOX, NaBoxClass)) -#define NA_IS_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NA_TYPE_BOX)) -#define NA_IS_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NA_TYPE_BOX)) -#define NA_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NA_TYPE_BOX, NaBoxClass)) - -typedef struct _NaBox NaBox; -typedef struct _NaBoxClass NaBoxClass; - -struct _NaBoxClass -{ - GtkBoxClass parent_class; -}; - -GType na_box_get_type (void); -GtkWidget *na_box_new (GtkOrientation orientation); -void na_box_force_redraw (NaBox *box); - -G_END_DECLS - -#endif /* __NA_TRAY_H__ */ diff --git a/applets/notification_area/na-grid.c b/applets/notification_area/na-grid.c new file mode 100644 index 00000000..1a491f52 --- /dev/null +++ b/applets/notification_area/na-grid.c @@ -0,0 +1,371 @@ +/* + * Copyright (C) 2002 Red Hat, Inc. + * Copyright (C) 2003-2006 Vincent Untz + * Copyright (C) 2007 Christian Persch + * Copyright (C) 2017 Colomban Wendling + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/* Well, actuall'y is the Tray itself, the container for the items. But + * NaTray is already taken for the XEMBED part, so for now it's called NaGrid, + * don't make a big deal out of it. */ + +#include "config.h" + +#include + +#include "na-grid.h" + +#include "system-tray/na-tray.h" +#include "status-notifier/sn-host-v0.h" + +#define ICON_SPACING 1 +#define MIN_GRID_SIZE 3 + +struct _NaGrid +{ + GtkBox parent; + + gint icon_padding; + gint icon_size; + + GSList *hosts; + GSList *items; +}; + +enum +{ + PROP_0, + PROP_ICON_PADDING, + PROP_ICON_SIZE +}; + +G_DEFINE_TYPE (NaGrid, na_grid, GTK_TYPE_BOX) + +static gint +compare_items (gconstpointer a, + gconstpointer b) +{ + NaItem *item1; + NaItem *item2; + NaItemCategory c1; + NaItemCategory c2; + const gchar *id1; + const gchar *id2; + + item1 = (NaItem *) a; + item2 = (NaItem *) b; + + c1 = na_item_get_category (item1); + c2 = na_item_get_category (item2); + + if (c1 < c2) + return -1; + else if (c1 > c2) + return 1; + + id1 = na_item_get_id (item1); + id2 = na_item_get_id (item2); + + return g_strcmp0 (id1, id2); +} + +static void +reorder_items (GtkWidget *widget, + gpointer user_data) +{ + NaGrid *nb; + gint position; + + nb = NA_GRID (user_data); + + position = g_slist_index (nb->items, widget); + gtk_box_reorder_child (GTK_BOX (nb), widget, position); +} + +static void +item_added_cb (NaHost *host, + NaItem *item, + NaGrid *self) +{ + g_return_if_fail (NA_IS_HOST (host)); + g_return_if_fail (NA_IS_ITEM (item)); + g_return_if_fail (NA_IS_GRID (self)); + + g_object_bind_property (self, "orientation", + item, "orientation", + G_BINDING_SYNC_CREATE); + + self->items = g_slist_prepend (self->items, item); + gtk_box_pack_start (GTK_BOX (self), GTK_WIDGET (item), FALSE, FALSE, 0); + + self->items = g_slist_sort (self->items, compare_items); + gtk_container_foreach (GTK_CONTAINER (self), reorder_items, self); +} + +static void +item_removed_cb (NaHost *host, + NaItem *item, + NaGrid *self) +{ + g_return_if_fail (NA_IS_HOST (host)); + g_return_if_fail (NA_IS_ITEM (item)); + g_return_if_fail (NA_IS_GRID (self)); + + gtk_container_remove (GTK_CONTAINER (self), GTK_WIDGET (item)); + self->items = g_slist_remove (self->items, item); +} + +static void +update_size_and_orientation (NaGrid *self, + GtkOrientation orientation) +{ + /* FIXME: do we really need that? comes from NaTray */ + /* FIXME: if we do, do that in overridden preferred size handlers */ + + /* note, you want this larger if the frame has non-NONE relief by default. */ + switch (orientation) + { + case GTK_ORIENTATION_VERTICAL: + /* Give grid a min size so the frame doesn't look dumb */ + gtk_widget_set_size_request (GTK_WIDGET (self), MIN_GRID_SIZE, -1); + break; + case GTK_ORIENTATION_HORIZONTAL: + gtk_widget_set_size_request (GTK_WIDGET (self), -1, MIN_GRID_SIZE); + break; + } +} + +static void +orientation_notify (GObject *object, + GParamSpec *pspec, + gpointer data) +{ + update_size_and_orientation (NA_GRID (object), + gtk_orientable_get_orientation (GTK_ORIENTABLE (object))); +} + +static void +na_grid_init (NaGrid *self) +{ + GtkOrientation orientation; + + self->icon_padding = 0; + self->icon_size = 0; + + self->hosts = NULL; + self->items = NULL; + + orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (self)); + update_size_and_orientation (self, orientation); + + g_signal_connect (self, "notify::orientation", G_CALLBACK (orientation_notify), NULL); +} + +static void +add_host (NaGrid *self, + NaHost *host) +{ + self->hosts = g_slist_prepend (self->hosts, host); + + g_object_bind_property (self, "icon-padding", host, "icon-padding", + G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); + g_object_bind_property (self, "icon-size", host, "icon-size", + G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); + + g_signal_connect_object (host, "item-added", + G_CALLBACK (item_added_cb), self, 0); + g_signal_connect_object (host, "item-removed", + G_CALLBACK (item_removed_cb), self, 0); +} + +static void +na_grid_style_updated (GtkWidget *widget) +{ + NaGrid *self = NA_GRID (widget); + GtkStyleContext *context; + GSList *node; + + if (GTK_WIDGET_CLASS (na_grid_parent_class)->style_updated) + GTK_WIDGET_CLASS (na_grid_parent_class)->style_updated (widget); + + context = gtk_widget_get_style_context (widget); + + for (node = self->hosts; node; node = node->next) + { + gtk_style_context_save (context); + na_host_style_updated (node->data, context); + gtk_style_context_restore (context); + } +} + +/* Custom drawing because system-tray items need weird stuff. */ +static gboolean +na_grid_draw (GtkWidget *grid, + cairo_t *cr) +{ + GList *child; + GList *children = gtk_container_get_children (GTK_CONTAINER (grid)); + + for (child = children; child; child = child->next) + { + if (! NA_IS_ITEM (child->data) || + ! na_item_draw_on_parent (child->data, grid, cr)) + { + if (gtk_widget_is_drawable (child->data) && + gtk_cairo_should_draw_window (cr, gtk_widget_get_window (child->data))) + gtk_container_propagate_draw (GTK_CONTAINER (grid), child->data, cr); + } + } + + g_list_free (children); + + return TRUE; +} + +static void +na_grid_realize (GtkWidget *widget) +{ + NaGrid *self = NA_GRID (widget); + GdkScreen *screen; + GtkOrientation orientation; + NaHost *tray_host; + + GTK_WIDGET_CLASS (na_grid_parent_class)->realize (widget); + + /* Instantiate the hosts now we have a screen */ + screen = gtk_widget_get_screen (GTK_WIDGET (self)); + orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (self)); + tray_host = na_tray_new_for_screen (screen, orientation); + g_object_bind_property (self, "orientation", + tray_host, "orientation", + G_BINDING_DEFAULT); + + add_host (self, tray_host); + add_host (self, sn_host_v0_new ()); +} + +static void +na_grid_unrealize (GtkWidget *widget) +{ + NaGrid *self = NA_GRID (widget); + + if (self->hosts != NULL) + { + g_slist_free_full (self->hosts, g_object_unref); + self->hosts = NULL; + } + + g_clear_pointer (&self->items, g_slist_free); + + GTK_WIDGET_CLASS (na_grid_parent_class)->unrealize (widget); +} + +static void +na_grid_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + NaGrid *self = NA_GRID (object); + + switch (property_id) + { + case PROP_ICON_PADDING: + g_value_set_int (value, self->icon_padding); + break; + + case PROP_ICON_SIZE: + g_value_set_int (value, self->icon_size); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +na_grid_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + NaGrid *self = NA_GRID (object); + + switch (property_id) + { + case PROP_ICON_PADDING: + self->icon_padding = g_value_get_int (value); + break; + + case PROP_ICON_SIZE: + self->icon_size = g_value_get_int (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +na_grid_class_init (NaGridClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gobject_class->get_property = na_grid_get_property; + gobject_class->set_property = na_grid_set_property; + + widget_class->draw = na_grid_draw; + widget_class->realize = na_grid_realize; + widget_class->unrealize = na_grid_unrealize; + widget_class->style_updated = na_grid_style_updated; + + g_object_class_install_property (gobject_class, PROP_ICON_PADDING, + g_param_spec_int ("icon-padding", + "Padding around icons", + "Padding that should be put around icons, in pixels", + 0, G_MAXINT, 0, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, PROP_ICON_SIZE, + g_param_spec_int ("icon-size", + "Icon size", + "If non-zero, hardcodes the size of the icons in pixels", + 0, G_MAXINT, 0, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +} + +GtkWidget * +na_grid_new (GtkOrientation orientation) +{ + return g_object_new (NA_TYPE_GRID, + "orientation", orientation, + "spacing", ICON_SPACING, + NULL); +} + +void +na_grid_force_redraw (NaGrid *grid) +{ + GSList *node; + + for (node = grid->hosts; node; node = node->next) + na_host_force_redraw (node->data); +} diff --git a/applets/notification_area/na-grid.h b/applets/notification_area/na-grid.h new file mode 100644 index 00000000..956d73c5 --- /dev/null +++ b/applets/notification_area/na-grid.h @@ -0,0 +1,43 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* na-tray-tray.h + * Copyright (C) 2002 Anders Carlsson + * Copyright (C) 2003-2006 Vincent Untz + * Copyright (C) 2017 Colomban Wendling + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * 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., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * Used to be: eggtraytray.h + */ + +#ifndef NA_GRID_H +#define NA_GRID_H + +#ifdef GDK_WINDOWING_X11 +#include +#endif +#include + +G_BEGIN_DECLS + +#define NA_TYPE_GRID (na_grid_get_type ()) +G_DECLARE_FINAL_TYPE (NaGrid, na_grid, NA, GRID, GtkBox) + +GtkWidget *na_grid_new (GtkOrientation orientation); +void na_grid_force_redraw (NaGrid *grid); + +G_END_DECLS + +#endif /* __NA_GRID_H__ */ diff --git a/applets/notification_area/testtray.c b/applets/notification_area/testtray.c index 80f8fba0..3f240ae0 100644 --- a/applets/notification_area/testtray.c +++ b/applets/notification_area/testtray.c @@ -30,7 +30,7 @@ #ifdef PROVIDE_WATCHER_SERVICE # include "libstatus-notifier-watcher/gf-status-notifier-watcher.h" #endif -#include "na-box.h" +#include "na-grid.h" #define NOTIFICATION_AREA_ICON "mate-panel-notification-area" @@ -181,7 +181,7 @@ create_tray_on_screen (GdkScreen *screen, gtk_label_set_yalign (GTK_LABEL (label), 0.5); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - data->traybox = na_box_new (GTK_ORIENTATION_HORIZONTAL); + data->traybox = na_grid_new (GTK_ORIENTATION_HORIZONTAL); gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (data->traybox), TRUE, TRUE, 0); g_signal_connect_after (data->traybox, "add", G_CALLBACK (tray_added_cb), data); -- cgit v1.2.1