2008-11-14 17:21:56 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2009-11-24 14:07:40 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-11-14 17:21:56 +00:00
|
|
|
#include <clutter/clutter.h>
|
2009-10-15 13:44:09 +00:00
|
|
|
#include <girepository.h>
|
2011-03-05 15:49:24 +00:00
|
|
|
#include <meta/display.h>
|
2009-10-15 13:44:09 +00:00
|
|
|
|
2008-11-14 17:21:56 +00:00
|
|
|
#include "shell-tray-manager.h"
|
|
|
|
#include "na-tray-manager.h"
|
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
#include "shell-tray-icon-private.h"
|
2009-10-15 13:44:09 +00:00
|
|
|
#include "shell-global.h"
|
2009-01-27 20:29:17 +00:00
|
|
|
|
2015-09-24 18:07:44 +00:00
|
|
|
typedef struct _ShellTrayManagerPrivate ShellTrayManagerPrivate;
|
|
|
|
|
|
|
|
struct _ShellTrayManager
|
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
|
|
ShellTrayManagerPrivate *priv;
|
|
|
|
};
|
|
|
|
|
2008-11-14 17:21:56 +00:00
|
|
|
struct _ShellTrayManagerPrivate {
|
|
|
|
NaTrayManager *na_manager;
|
2008-11-24 19:07:15 +00:00
|
|
|
ClutterColor bg_color;
|
2008-11-14 17:21:56 +00:00
|
|
|
|
|
|
|
GHashTable *icons;
|
2020-03-04 22:26:15 +00:00
|
|
|
StWidget *theme_widget;
|
2008-11-14 17:21:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ShellTrayManager *manager;
|
2022-12-22 19:02:28 +00:00
|
|
|
NaTrayChild *tray_child;
|
2008-11-14 17:21:56 +00:00
|
|
|
ClutterActor *actor;
|
|
|
|
} ShellTrayManagerChild;
|
|
|
|
|
2008-11-24 19:07:15 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_BG_COLOR
|
|
|
|
};
|
|
|
|
|
2008-11-14 17:21:56 +00:00
|
|
|
/* Signals */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TRAY_ICON_ADDED,
|
|
|
|
TRAY_ICON_REMOVED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2015-09-24 16:56:13 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (ShellTrayManager, shell_tray_manager, G_TYPE_OBJECT);
|
2008-11-14 17:21:56 +00:00
|
|
|
|
|
|
|
static guint shell_tray_manager_signals [LAST_SIGNAL] = { 0 };
|
|
|
|
|
2010-03-31 20:40:32 +00:00
|
|
|
static const ClutterColor default_color = { 0x00, 0x00, 0x00, 0xff };
|
2008-11-24 19:07:15 +00:00
|
|
|
|
2020-03-04 22:12:29 +00:00
|
|
|
static void shell_tray_manager_release_resources (ShellTrayManager *manager);
|
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
static void na_tray_icon_added (NaTrayManager *na_manager,
|
|
|
|
NaTrayChild *child,
|
|
|
|
gpointer manager);
|
|
|
|
|
|
|
|
static void na_tray_icon_removed (NaTrayManager *na_manager,
|
|
|
|
NaTrayChild *child,
|
|
|
|
gpointer manager);
|
2008-11-14 17:21:56 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
free_tray_icon (gpointer data)
|
|
|
|
{
|
|
|
|
ShellTrayManagerChild *child = data;
|
|
|
|
|
2010-10-24 12:26:50 +00:00
|
|
|
if (child->actor)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_matched (child->actor, G_SIGNAL_MATCH_DATA,
|
|
|
|
0, 0, NULL, NULL, child);
|
|
|
|
g_object_unref (child->actor);
|
|
|
|
}
|
2020-10-19 18:12:27 +00:00
|
|
|
g_free (child);
|
2008-11-14 17:21:56 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 19:07:15 +00:00
|
|
|
static void
|
|
|
|
shell_tray_manager_set_property(GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ShellTrayManager *manager = SHELL_TRAY_MANAGER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BG_COLOR:
|
|
|
|
{
|
|
|
|
ClutterColor *color = g_value_get_boxed (value);
|
|
|
|
if (color)
|
|
|
|
manager->priv->bg_color = *color;
|
|
|
|
else
|
|
|
|
manager->priv->bg_color = default_color;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_tray_manager_get_property(GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ShellTrayManager *manager = SHELL_TRAY_MANAGER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BG_COLOR:
|
|
|
|
g_value_set_boxed (value, &manager->priv->bg_color);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-14 17:21:56 +00:00
|
|
|
static void
|
|
|
|
shell_tray_manager_init (ShellTrayManager *manager)
|
|
|
|
{
|
2015-09-24 16:56:13 +00:00
|
|
|
manager->priv = shell_tray_manager_get_instance_private (manager);
|
|
|
|
|
2008-11-24 19:07:15 +00:00
|
|
|
manager->priv->bg_color = default_color;
|
2008-11-14 17:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_tray_manager_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
ShellTrayManager *manager = SHELL_TRAY_MANAGER (object);
|
|
|
|
|
2020-03-04 22:12:29 +00:00
|
|
|
shell_tray_manager_release_resources (manager);
|
2008-11-14 17:21:56 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (shell_tray_manager_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_tray_manager_class_init (ShellTrayManagerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = shell_tray_manager_finalize;
|
2008-11-24 19:07:15 +00:00
|
|
|
gobject_class->set_property = shell_tray_manager_set_property;
|
|
|
|
gobject_class->get_property = shell_tray_manager_get_property;
|
2008-11-14 17:21:56 +00:00
|
|
|
|
|
|
|
shell_tray_manager_signals[TRAY_ICON_ADDED] =
|
|
|
|
g_signal_new ("tray-icon-added",
|
2009-10-15 13:44:09 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2015-10-15 20:13:18 +00:00
|
|
|
0,
|
2011-10-18 22:19:32 +00:00
|
|
|
NULL, NULL, NULL,
|
2010-09-08 02:27:08 +00:00
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
CLUTTER_TYPE_ACTOR);
|
2008-11-14 17:21:56 +00:00
|
|
|
shell_tray_manager_signals[TRAY_ICON_REMOVED] =
|
|
|
|
g_signal_new ("tray-icon-removed",
|
2009-10-15 13:44:09 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2015-10-15 20:13:18 +00:00
|
|
|
0,
|
2011-10-18 22:19:32 +00:00
|
|
|
NULL, NULL, NULL,
|
2009-10-15 13:44:09 +00:00
|
|
|
G_TYPE_NONE, 1,
|
2008-11-14 17:21:56 +00:00
|
|
|
CLUTTER_TYPE_ACTOR);
|
2008-11-24 19:07:15 +00:00
|
|
|
|
|
|
|
/* Lifting the CONSTRUCT_ONLY here isn't hard; you just need to
|
|
|
|
* iterate through the icons, reset the background pixmap, and
|
|
|
|
* call na_tray_child_force_redraw()
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_BG_COLOR,
|
|
|
|
g_param_spec_boxed ("bg-color",
|
|
|
|
"BG Color",
|
|
|
|
"Background color (only if we don't have transparency)",
|
|
|
|
CLUTTER_TYPE_COLOR,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2008-11-14 17:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ShellTrayManager *
|
|
|
|
shell_tray_manager_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (SHELL_TYPE_TRAY_MANAGER, NULL);
|
|
|
|
}
|
|
|
|
|
2020-03-04 22:12:29 +00:00
|
|
|
static void
|
|
|
|
shell_tray_manager_ensure_resources (ShellTrayManager *manager)
|
|
|
|
{
|
2022-12-22 19:02:28 +00:00
|
|
|
MetaDisplay *display;
|
|
|
|
MetaX11Display *x11_display;
|
|
|
|
|
2020-03-04 22:12:29 +00:00
|
|
|
if (manager->priv->na_manager != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
manager->priv->icons = g_hash_table_new_full (NULL, NULL,
|
|
|
|
NULL, free_tray_icon);
|
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
display = shell_global_get_display (shell_global_get ());
|
|
|
|
x11_display = meta_display_get_x11_display (display);
|
|
|
|
|
|
|
|
manager->priv->na_manager = na_tray_manager_new (x11_display);
|
2020-03-04 22:12:29 +00:00
|
|
|
|
|
|
|
g_signal_connect (manager->priv->na_manager, "tray-icon-added",
|
|
|
|
G_CALLBACK (na_tray_icon_added), manager);
|
|
|
|
g_signal_connect (manager->priv->na_manager, "tray-icon-removed",
|
|
|
|
G_CALLBACK (na_tray_icon_removed), manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_tray_manager_release_resources (ShellTrayManager *manager)
|
|
|
|
{
|
|
|
|
g_clear_object (&manager->priv->na_manager);
|
|
|
|
g_clear_pointer (&manager->priv->icons, g_hash_table_destroy);
|
|
|
|
}
|
|
|
|
|
2011-01-31 17:48:18 +00:00
|
|
|
static void
|
|
|
|
shell_tray_manager_style_changed (StWidget *theme_widget,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ShellTrayManager *manager = user_data;
|
|
|
|
StThemeNode *theme_node;
|
|
|
|
StIconColors *icon_colors;
|
|
|
|
|
2020-03-04 13:27:54 +00:00
|
|
|
if (manager->priv->na_manager == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-01-31 17:48:18 +00:00
|
|
|
theme_node = st_widget_get_theme_node (theme_widget);
|
|
|
|
icon_colors = st_theme_node_get_icon_colors (theme_node);
|
|
|
|
na_tray_manager_set_colors (manager->priv->na_manager,
|
2015-09-25 20:31:17 +00:00
|
|
|
&icon_colors->foreground, &icon_colors->warning,
|
|
|
|
&icon_colors->error, &icon_colors->success);
|
2011-01-31 17:48:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 13:27:54 +00:00
|
|
|
static void
|
|
|
|
shell_tray_manager_manage_screen_internal (ShellTrayManager *manager)
|
|
|
|
{
|
|
|
|
shell_tray_manager_ensure_resources (manager);
|
2022-12-22 19:02:28 +00:00
|
|
|
na_tray_manager_manage (manager->priv->na_manager);
|
2020-03-04 13:27:54 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 17:21:56 +00:00
|
|
|
void
|
2013-02-12 22:31:38 +00:00
|
|
|
shell_tray_manager_manage_screen (ShellTrayManager *manager,
|
|
|
|
StWidget *theme_widget)
|
2008-11-14 17:21:56 +00:00
|
|
|
{
|
2020-03-04 13:27:54 +00:00
|
|
|
MetaDisplay *display = shell_global_get_display (shell_global_get ());
|
|
|
|
|
2020-03-04 22:26:15 +00:00
|
|
|
g_set_weak_pointer (&manager->priv->theme_widget, theme_widget);
|
|
|
|
|
2020-03-04 13:27:54 +00:00
|
|
|
if (meta_display_get_x11_display (display) != NULL)
|
|
|
|
shell_tray_manager_manage_screen_internal (manager);
|
2020-03-04 22:12:29 +00:00
|
|
|
|
2020-03-04 13:27:54 +00:00
|
|
|
g_signal_connect_object (display, "x11-display-setup",
|
|
|
|
G_CALLBACK (shell_tray_manager_manage_screen_internal),
|
|
|
|
manager, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (display, "x11-display-closing",
|
|
|
|
G_CALLBACK (shell_tray_manager_release_resources),
|
|
|
|
manager, G_CONNECT_SWAPPED);
|
2011-01-31 17:48:18 +00:00
|
|
|
|
2017-08-19 18:56:15 +00:00
|
|
|
g_signal_connect_object (theme_widget, "style-changed",
|
|
|
|
G_CALLBACK (shell_tray_manager_style_changed),
|
|
|
|
manager, 0);
|
2011-01-31 17:48:18 +00:00
|
|
|
shell_tray_manager_style_changed (theme_widget, manager);
|
2008-11-14 17:21:56 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:26:15 +00:00
|
|
|
void
|
|
|
|
shell_tray_manager_unmanage_screen (ShellTrayManager *manager)
|
|
|
|
{
|
2020-03-04 13:27:54 +00:00
|
|
|
MetaDisplay *display = shell_global_get_display (shell_global_get ());
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_data (display, manager);
|
|
|
|
|
2020-03-04 22:26:15 +00:00
|
|
|
if (manager->priv->theme_widget != NULL)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (manager->priv->theme_widget,
|
|
|
|
G_CALLBACK (shell_tray_manager_style_changed),
|
|
|
|
manager);
|
|
|
|
}
|
|
|
|
g_set_weak_pointer (&manager->priv->theme_widget, NULL);
|
|
|
|
|
|
|
|
shell_tray_manager_release_resources (manager);
|
|
|
|
}
|
|
|
|
|
2009-05-03 17:05:15 +00:00
|
|
|
static void
|
2022-12-22 19:02:28 +00:00
|
|
|
on_plug_added (NaTrayChild *tray_child,
|
2009-10-15 13:44:09 +00:00
|
|
|
ShellTrayManager *manager)
|
|
|
|
{
|
|
|
|
ShellTrayManagerChild *child;
|
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (tray_child, on_plug_added, manager);
|
2009-10-15 13:44:09 +00:00
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
child = g_hash_table_lookup (manager->priv->icons, tray_child);
|
2010-08-10 15:12:36 +00:00
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
child->actor = shell_tray_icon_new (tray_child);
|
2010-11-18 02:30:31 +00:00
|
|
|
g_object_ref_sink (child->actor);
|
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
na_xembed_set_background_color (NA_XEMBED (tray_child),
|
|
|
|
&manager->priv->bg_color);
|
|
|
|
|
2009-10-15 13:44:09 +00:00
|
|
|
g_signal_emit (manager, shell_tray_manager_signals[TRAY_ICON_ADDED], 0,
|
2010-09-08 02:27:08 +00:00
|
|
|
child->actor);
|
2009-10-15 13:44:09 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 17:21:56 +00:00
|
|
|
static void
|
2022-12-22 19:02:28 +00:00
|
|
|
na_tray_icon_added (NaTrayManager *na_manager,
|
|
|
|
NaTrayChild *tray_child,
|
|
|
|
gpointer user_data)
|
2008-11-14 17:21:56 +00:00
|
|
|
{
|
|
|
|
ShellTrayManager *manager = user_data;
|
|
|
|
ShellTrayManagerChild *child;
|
|
|
|
|
2020-10-19 18:12:27 +00:00
|
|
|
child = g_new0 (ShellTrayManagerChild, 1);
|
2009-05-05 18:07:11 +00:00
|
|
|
child->manager = manager;
|
2022-12-22 19:02:28 +00:00
|
|
|
child->tray_child = tray_child;
|
2008-11-24 19:07:15 +00:00
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
g_hash_table_insert (manager->priv->icons, tray_child, child);
|
2008-11-14 17:21:56 +00:00
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
g_signal_connect (tray_child, "plug-added",
|
|
|
|
G_CALLBACK (on_plug_added), manager);
|
2008-11-14 17:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-12-22 19:02:28 +00:00
|
|
|
na_tray_icon_removed (NaTrayManager *na_manager,
|
|
|
|
NaTrayChild *tray_child,
|
|
|
|
gpointer user_data)
|
2008-11-14 17:21:56 +00:00
|
|
|
{
|
|
|
|
ShellTrayManager *manager = user_data;
|
|
|
|
ShellTrayManagerChild *child;
|
|
|
|
|
2022-12-22 19:02:28 +00:00
|
|
|
child = g_hash_table_lookup (manager->priv->icons, tray_child);
|
2008-11-14 17:21:56 +00:00
|
|
|
g_return_if_fail (child != NULL);
|
|
|
|
|
2010-10-24 12:26:50 +00:00
|
|
|
if (child->actor != NULL)
|
|
|
|
{
|
|
|
|
/* Only emit signal if a corresponding tray-icon-added signal was emitted,
|
2022-12-22 19:02:28 +00:00
|
|
|
* that is, if embedding did not fail and we got a plug-added
|
|
|
|
*/
|
2010-10-24 12:26:50 +00:00
|
|
|
g_signal_emit (manager,
|
|
|
|
shell_tray_manager_signals[TRAY_ICON_REMOVED], 0,
|
|
|
|
child->actor);
|
|
|
|
}
|
2022-12-22 19:02:28 +00:00
|
|
|
|
|
|
|
g_hash_table_remove (manager->priv->icons, tray_child);
|
2008-11-14 17:21:56 +00:00
|
|
|
}
|