Back to index

unity  6.0.0
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
unity::PanelTray Class Reference

#include <PanelTray.h>

Inheritance diagram for unity::PanelTray:
Inheritance graph
[legend]
Collaboration diagram for unity::PanelTray:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 PanelTray ()
 ~PanelTray ()
void Sync ()
Window xid ()
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
virtual IntrospectableList GetIntrospectableChildren ()
guint64 GetIntrospectionId () const

Protected Member Functions

void Draw (nux::GraphicsEngine &gfx_content, bool force_draw)
std::string GetName () const
void AddProperties (GVariantBuilder *builder)
virtual std::string GetChildsName () const
 Please don't override this unless you really need to. The only valid reason is if you have a property that simply must be called 'Children'.

Private Member Functions

bool IdleSync ()
void OnTrayIconRemoved (NaTrayManager *manager, NaTrayChild *child)
gboolean OnTrayDraw (GtkWidget *widget, cairo_t *cr)
int WidthOfTray ()

Static Private Member Functions

static gboolean FilterTrayCallback (NaTray *tray, NaTrayChild *child, PanelTray *self)

Private Attributes

glib::Object< GSettings > settings_
glib::Object< GtkWidget > window_
glib::Object< NaTray > tray_
char ** whitelist_
glib::Signal< void, GSettings
*, gchar * > 
whitelist_changed_
glib::Signal< gboolean,
GtkWidget *, cairo_t * > 
draw_signal_
glib::Signal< void,
NaTrayManager *, NaTrayChild * > 
icon_removed_signal_
glib::Source::UniquePtr sync_idle_
std::list< NaTrayChild * > children_
nux::Geometry last_geo_

Detailed Description

Definition at line 40 of file PanelTray.h.


Member Typedef Documentation

Definition at line 34 of file Introspectable.h.


Constructor & Destructor Documentation

Definition at line 36 of file PanelTray.cpp.

  : View(NUX_TRACKER_LOCATION)
  , settings_(g_settings_new(SETTINGS_NAME.c_str()))
  , window_(gtk_window_new(GTK_WINDOW_TOPLEVEL))
  , whitelist_(g_settings_get_strv(settings_, "systray-whitelist"))
{
  int panel_height = panel::Style::Instance().panel_height;

  whitelist_changed_.Connect(settings_, "changed::systray-whitelist", [&] (GSettings*, gchar*) {
    g_strfreev(whitelist_);
    whitelist_ = g_settings_get_strv(settings_, "systray-whitelist");
  });

  auto gtkwindow = glib::object_cast<GtkWindow>(window_);
  gtk_window_set_type_hint(gtkwindow, GDK_WINDOW_TYPE_HINT_DOCK);
  gtk_window_set_has_resize_grip(gtkwindow, FALSE);
  gtk_window_set_keep_above(gtkwindow, TRUE);
  gtk_window_set_skip_pager_hint(gtkwindow, TRUE);
  gtk_window_set_skip_taskbar_hint(gtkwindow, TRUE);
  gtk_window_resize(gtkwindow, 1, panel_height);
  gtk_window_move(gtkwindow, -panel_height,-panel_height);
  gtk_widget_set_name(window_, "UnityPanelApplet");

  gtk_widget_set_visual(window_, gdk_screen_get_rgba_visual(gdk_screen_get_default()));
  gtk_widget_realize(window_);
  gtk_widget_set_app_paintable(window_, TRUE);
  draw_signal_.Connect(window_, "draw", sigc::mem_fun(this, &PanelTray::OnTrayDraw));

  if (!g_getenv("UNITY_PANEL_TRAY_DISABLE"))
  {
    tray_ = na_tray_new_for_screen(gdk_screen_get_default(),
                                   GTK_ORIENTATION_HORIZONTAL,
                                   (NaTrayFilterCallback)FilterTrayCallback,
                                   this);
    na_tray_set_icon_size(tray_, panel_height);

    icon_removed_signal_.Connect(na_tray_get_manager(tray_), "tray_icon_removed",
                                 sigc::mem_fun(this, &PanelTray::OnTrayIconRemoved));

    gtk_container_add(GTK_CONTAINER(window_.RawPtr()), GTK_WIDGET(tray_.RawPtr()));
    gtk_widget_show(GTK_WIDGET(tray_.RawPtr()));
  }

  SetMinMaxSize(1, panel_height);
}

Here is the call graph for this function:

Definition at line 82 of file PanelTray.cpp.

{
  g_strfreev(whitelist_);

  if (gtk_widget_get_realized(window_))
  {
    // We call Release since we're deleting the window here manually,
    // and we don't want the smart pointer to try and delete it as well.
    gtk_widget_destroy(window_.Release());
  }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 78 of file Introspectable.cpp.

{
  _children.push_back(child);
  child->_parents.push_back(this);
}

Here is the caller graph for this function:

void unity::PanelTray::AddProperties ( GVariantBuilder *  builder) [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 243 of file PanelTray.cpp.

{
  variant::BuilderWrapper(builder)
  .add(GetAbsoluteGeometry())
  .add("children_count", children_.size());
}

Here is the call graph for this function:

void unity::PanelTray::Draw ( nux::GraphicsEngine &  gfx_content,
bool  force_draw 
) [protected]

Definition at line 102 of file PanelTray.cpp.

{
  nux::Geometry const& geo = GetAbsoluteGeometry();

  gfx_context.PushClippingRectangle(geo);
  nux::GetPainter().PaintBackground(gfx_context, geo);
  gfx_context.PopClippingRectangle();

  if (geo != last_geo_)
  {
    last_geo_ = geo;
    gtk_window_move(GTK_WINDOW(window_.RawPtr()), geo.x + PADDING, geo.y);
  }
}

Here is the call graph for this function:

gboolean unity::PanelTray::FilterTrayCallback ( NaTray *  tray,
NaTrayChild *  child,
PanelTray self 
) [static, private]

Definition at line 132 of file PanelTray.cpp.

{
  int i = 0;
  bool accept = false;
  const char *name = nullptr;

  glib::String title(na_tray_child_get_title(icon));

  glib::String res_class;
  glib::String res_name;
  na_tray_child_get_wm_class(icon, &res_name, &res_class);

  while ((name = self->whitelist_[i]))
  {
    if (g_strcmp0(name, "all") == 0)
    {
      accept = true;
      break;
    }
    else if (!name || name[0] == '\0')
    {
      accept = false;
      break;
    }
    else if ((title && g_str_has_prefix(title, name))
             || (res_name && g_str_has_prefix(res_name, name))
             || (res_class && g_str_has_prefix(res_class, name)))
    {
      accept = true;
      break;
    }

    i++;
  }

  if (accept)
  {
    if (na_tray_child_has_alpha(icon))
      na_tray_child_set_composited(icon, TRUE);

    self->children_.push_back(icon);
    self->sync_idle_.reset(new glib::Idle(sigc::mem_fun(self, &PanelTray::IdleSync)));
  }

  LOG_DEBUG(logger) << "TrayChild "
                    << (accept ? "Accepted: " : "Rejected: ")
                    << na_tray_child_get_title(icon) << " "
                    << res_name << " " << res_class;

  return accept ? TRUE : FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::string unity::debug::Introspectable::GetChildsName ( ) const [protected, virtual, inherited]

Please don't override this unless you really need to. The only valid reason is if you have a property that simply must be called 'Children'.

Definition at line 92 of file Introspectable.cpp.

{
  return "Children";
}

Here is the caller graph for this function:

Introspectable::IntrospectableList unity::debug::Introspectable::GetIntrospectableChildren ( ) [virtual, inherited]

Reimplemented in unity::hud::View, unity::launcher::LauncherModel, unity::QuicklistView, and unity::dash::ResultView.

Definition at line 41 of file Introspectable.cpp.

{
  return _children;
}

Here is the caller graph for this function:

guint64 unity::debug::Introspectable::GetIntrospectionId ( ) const [inherited]

Definition at line 97 of file Introspectable.cpp.

{
  return _id;
}

Here is the caller graph for this function:

std::string unity::PanelTray::GetName ( ) const [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 238 of file PanelTray.cpp.

{
  return "Tray";
}
bool unity::PanelTray::IdleSync ( ) [private]

Definition at line 197 of file PanelTray.cpp.

{
  int width = WidthOfTray();
  gtk_window_resize(GTK_WINDOW(window_.RawPtr()), width, panel::Style::Instance().panel_height);
  Sync();

  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

GVariant * unity::debug::Introspectable::Introspect ( ) [inherited]

Definition at line 47 of file Introspectable.cpp.

{
  GVariantBuilder  builder;
  GVariantBuilder  child_builder;
  gint             n_children = 0;

  g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
  g_variant_builder_add(&builder, "{sv}", "id", g_variant_new_uint64(_id));

  AddProperties(&builder);

  g_variant_builder_init(&child_builder, G_VARIANT_TYPE("as"));

  auto children = GetIntrospectableChildren();
  for (auto it = children.begin(); it != children.end(); it++)
  {
    if ((*it)->GetName() != "")
    {
      g_variant_builder_add(&child_builder, "s", (*it)->GetName().c_str());
      n_children++;
    }
  }

  GVariant* child_results = g_variant_builder_end(&child_builder);

  if (n_children > 0)
    g_variant_builder_add(&builder, "{sv}", GetChildsName().c_str(), child_results);
  return g_variant_builder_end(&builder);
}

Here is the call graph for this function:

gboolean unity::PanelTray::OnTrayDraw ( GtkWidget *  widget,
cairo_t *  cr 
) [private]

Definition at line 217 of file PanelTray.cpp.

{
  GtkAllocation alloc;

  gtk_widget_get_allocation(widget, &alloc);

  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);

  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
  cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
  cairo_rectangle(cr, 0, 0, alloc.width, alloc.height);
  cairo_fill(cr);

  gtk_container_propagate_draw(GTK_CONTAINER(widget),
                               gtk_bin_get_child(GTK_BIN(widget)),
                               cr);

  return FALSE;
}

Here is the caller graph for this function:

void unity::PanelTray::OnTrayIconRemoved ( NaTrayManager *  manager,
NaTrayChild *  child 
) [private]

Definition at line 184 of file PanelTray.cpp.

{
  for (auto child : children_)
  {
    if (child == removed)
    {
      sync_idle_.reset(new glib::Idle(sigc::mem_fun(this, &PanelTray::IdleSync)));
      children_.remove(child);
      break;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 85 of file Introspectable.cpp.

{
  _children.remove(child);
  child->_parents.remove(this);
}

Here is the caller graph for this function:

Definition at line 117 of file PanelTray.cpp.

{
  if (tray_)
  {
    SetMinMaxSize(WidthOfTray() + (PADDING * 2), panel::Style::Instance().panel_height);
    QueueRelayout();
    QueueDraw();

    if (!children_.empty())
      gtk_widget_show(window_);
    else
      gtk_widget_hide(window_);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int unity::PanelTray::WidthOfTray ( ) [private]

Definition at line 206 of file PanelTray.cpp.

{
  int width = 0;
  for (auto child: children_)
  {
    int w = gtk_widget_get_allocated_width(GTK_WIDGET(child));
    width += w > 24 ? w : 24;
  }
  return width;
}

Here is the caller graph for this function:

Definition at line 94 of file PanelTray.cpp.

{
  if (!window_)
    return 0;

  return gdk_x11_window_get_xid(gtk_widget_get_window(window_));
}

Here is the caller graph for this function:


Member Data Documentation

std::list<NaTrayChild*> unity::PanelTray::children_ [private]

Definition at line 71 of file PanelTray.h.

glib::Signal<gboolean, GtkWidget*, cairo_t*> unity::PanelTray::draw_signal_ [private]

Definition at line 68 of file PanelTray.h.

glib::Signal<void, NaTrayManager*, NaTrayChild*> unity::PanelTray::icon_removed_signal_ [private]

Definition at line 69 of file PanelTray.h.

nux::Geometry unity::PanelTray::last_geo_ [private]

Definition at line 72 of file PanelTray.h.

Definition at line 62 of file PanelTray.h.

Definition at line 70 of file PanelTray.h.

Definition at line 64 of file PanelTray.h.

char** unity::PanelTray::whitelist_ [private]

Definition at line 65 of file PanelTray.h.

glib::Signal<void, GSettings*, gchar*> unity::PanelTray::whitelist_changed_ [private]

Definition at line 67 of file PanelTray.h.

Definition at line 63 of file PanelTray.h.


The documentation for this class was generated from the following files: