Back to index

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

#include <SwitcherController.h>

Inheritance diagram for unity::switcher::Controller:
Inheritance graph
[legend]
Collaboration diagram for unity::switcher::Controller:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::shared_ptr
< Controller
Ptr
typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 Controller (unsigned int load_timeout=20)
void Show (ShowMode show, SortMode sort, bool reverse, std::vector< launcher::AbstractLauncherIcon::Ptr > results)
void Hide (bool accept_state=true)
bool Visible ()
void Next ()
void Prev ()
void NextDetail ()
void PrevDetail ()
void Select (int index)
void SetDetail (bool detail, unsigned int min_windows=1)
void SelectFirstItem ()
void SetWorkspace (nux::Geometry geo, int monitor)
SwitcherViewGetView ()
ui::LayoutWindowList ExternalRenderTargets ()
guint GetSwitcherInputWindowId () const
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
virtual IntrospectableList GetIntrospectableChildren ()
guint64 GetIntrospectionId () const

Public Attributes

nux::Property< int > timeout_length
nux::Property< bool > detail_on_timeout
nux::Property< int > detail_timeout_length
nux::Property< int > initial_detail_timeout_length

Protected Member Functions

std::string GetName () const
void AddProperties (GVariantBuilder *builder)
virtual void ConstructWindow ()
virtual void ConstructView ()
virtual void ShowView ()
virtual bool OnDetailTimer ()
void OnModelSelectionChanged (launcher::AbstractLauncherIcon::Ptr icon)
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'.

Protected Attributes

unsigned int construct_timeout_

Private Types

enum  DetailMode { TAB_NEXT_WINDOW, TAB_NEXT_WINDOW_LOOP, TAB_NEXT_TILE }

Private Member Functions

void OnBackgroundUpdate (GVariant *data)

Static Private Member Functions

static bool CompareSwitcherItemsPriority (launcher::AbstractLauncherIcon::Ptr first, launcher::AbstractLauncherIcon::Ptr second)

Private Attributes

SwitcherModel::Ptr model_
SwitcherView::Ptr view_
nux::Geometry workarea_
nux::ObjectPtr< nux::BaseWindow > view_window_
nux::HLayout * main_layout_
int monitor_
bool visible_
nux::Color bg_color_
DetailMode detail_mode_
UBusManager ubus_manager_
glib::SourceManager sources_

Detailed Description

Definition at line 58 of file SwitcherController.h.


Member Typedef Documentation

Definition at line 34 of file Introspectable.h.

typedef std::shared_ptr<Controller> unity::switcher::Controller::Ptr

Definition at line 61 of file SwitcherController.h.


Member Enumeration Documentation

Enumerator:
TAB_NEXT_WINDOW 
TAB_NEXT_WINDOW_LOOP 
TAB_NEXT_TILE 

Definition at line 110 of file SwitcherController.h.


Constructor & Destructor Documentation

unity::switcher::Controller::Controller ( unsigned int  load_timeout = 20)

Definition at line 46 of file SwitcherController.cpp.

  :  timeout_length(75)
  ,  detail_on_timeout(true)
  ,  detail_timeout_length(500)
  ,  initial_detail_timeout_length(1500)
  ,  construct_timeout_(load_timeout)
  ,  main_layout_(nullptr)
  ,  monitor_(0)
  ,  visible_(false)
  ,  bg_color_(0, 0, 0, 0.5)
{
  ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &Controller::OnBackgroundUpdate));

  auto lazy_timeout = std::make_shared<glib::TimeoutSeconds>(construct_timeout_, glib::Source::Priority::LOW);
  lazy_timeout->Run([&] { ConstructWindow(); return false; });
  sources_.Add(lazy_timeout, LAZY_TIMEOUT);
}

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::switcher::Controller::AddProperties ( GVariantBuilder *  builder) [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 473 of file SwitcherController.cpp.

{
  unity::variant::BuilderWrapper(builder)
  .add("timeout-length", timeout_length())
  .add("detail-on-timeout", detail_on_timeout())
  .add("initial-detail-timeout-length", initial_detail_timeout_length())
  .add("detail-timeout-length", detail_timeout_length())
  .add("visible", visible_)
  .add("monitor", monitor_)
  .add("detail-mode", detail_mode_);
}

Here is the call graph for this function:

Definition at line 401 of file SwitcherController.cpp.

{
  if (first->GetIconType() == second->GetIconType())
    return first->SwitcherPriority() > second->SwitcherPriority();

  if (first->GetIconType() == AbstractLauncherIcon::IconType::TYPE_DESKTOP)
    return true;

  if (second->GetIconType() == AbstractLauncherIcon::IconType::TYPE_DESKTOP)
    return false;

  return first->GetIconType() < second->GetIconType();
}
void unity::switcher::Controller::ConstructView ( ) [protected, virtual]

Definition at line 189 of file SwitcherController.cpp.

{
  if (view_ || !model_)
    return;

  sources_.Remove(VIEW_CONSTRUCT_IDLE);

  view_ = SwitcherView::Ptr(new SwitcherView());
  AddChild(view_.GetPointer());
  view_->SetModel(model_);
  view_->background_color = bg_color_;
  view_->monitor = monitor_;
  view_->SetupBackground();

  ConstructWindow();
  main_layout_->AddView(view_.GetPointer(), 1);
  view_window_->SetGeometry(workarea_);
  view_window_->SetOpacity(0.0f);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::switcher::Controller::ConstructWindow ( ) [protected, virtual]

Definition at line 171 of file SwitcherController.cpp.

{
  sources_.Remove(LAZY_TIMEOUT);

  if (!view_window_)
  {
    main_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
    main_layout_->SetVerticalExternalMargin(0);
    main_layout_->SetHorizontalExternalMargin(0);

    view_window_ = new nux::BaseWindow("Switcher");
    view_window_->SetLayout(main_layout_);
    view_window_->SetBackgroundColor(nux::Color(0x00000000));
    view_window_->SetGeometry(workarea_);
    view_window_->EnableInputWindow(true, "Switcher", false, false);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 386 of file SwitcherController.cpp.

{
  if (!view_)
  {
    LayoutWindowList result;
    return result;
  }
  return view_->ExternalTargets();
}
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::switcher::Controller::GetName ( ) const [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 467 of file SwitcherController.cpp.

{
  return "SwitcherController";
}

Definition at line 396 of file SwitcherController.cpp.

{
  return view_window_->GetInputWindowId();
}

Definition at line 335 of file SwitcherController.cpp.

{
  return view_.GetPointer();
}

Here is the caller graph for this function:

void unity::switcher::Controller::Hide ( bool  accept_state = true)

Definition at line 218 of file SwitcherController.cpp.

{
  if (!visible_)
    return;

  if (accept_state)
  {
    AbstractLauncherIcon::Ptr selection = model_->Selection();
    if (selection)
    {
      if (model_->detail_selection)
      {
        selection->Activate(ActionArg(ActionArg::SWITCHER, 0, model_->DetailSelectionWindow ()));
      }
      else
      {
        if (selection->GetQuirk (AbstractLauncherIcon::QUIRK_ACTIVE) &&
            !model_->DetailXids().empty ())
        {
          selection->Activate(ActionArg (ActionArg::SWITCHER, 0, model_->DetailXids()[0]));
        }
        else
        {
          selection->Activate(ActionArg(ActionArg::SWITCHER, 0));
        }
      }
    }
  }

  ubus_manager_.SendMessage(UBUS_SWITCHER_END, g_variant_new_boolean(!accept_state));

  sources_.Remove(VIEW_CONSTRUCT_IDLE);
  sources_.Remove(SHOW_TIMEOUT);
  sources_.Remove(DETAIL_TIMEOUT);

  model_.reset();
  visible_ = false;

  if (view_)
    main_layout_->RemoveChildObject(view_.GetPointer());

  if (view_window_)
  {
    view_window_->SetOpacity(0.0f);
    view_window_->ShowWindow(false);
    view_window_->PushToBack();
    view_window_->EnableInputWindow(false);
  }

  ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new("(bi)", false, monitor_));

  view_.Release();
}

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:

Definition at line 277 of file SwitcherController.cpp.

{
  if (!model_)
    return;

  if (model_->detail_selection)
  {
    switch (detail_mode_)
    {
      case TAB_NEXT_WINDOW:
        if (model_->detail_selection_index < model_->DetailXids().size () - 1)
          model_->NextDetail();
        else
          model_->Next();
        break;
      case TAB_NEXT_TILE:
        model_->Next();
        break;
      case TAB_NEXT_WINDOW_LOOP:
        model_->NextDetail(); //looping automatic
        break;
    }
  }
  else
  {
    model_->Next();
  }
}

Here is the caller graph for this function:

Definition at line 353 of file SwitcherController.cpp.

{
  if (!model_)
    return;

  if (!model_->detail_selection)
  {
    SetDetail(true);
    detail_mode_ = TAB_NEXT_TILE;
  }
  else
  {
    model_->NextDetail();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::switcher::Controller::OnBackgroundUpdate ( GVariant *  data) [private]

Definition at line 64 of file SwitcherController.cpp.

{
  gdouble red, green, blue, alpha;
  g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha);
  bg_color_ = nux::Color(red, green, blue, alpha);

  if (view_)
    view_->background_color = bg_color_;
}

Here is the caller graph for this function:

bool unity::switcher::Controller::OnDetailTimer ( ) [protected, virtual]

Definition at line 123 of file SwitcherController.cpp.

{
  if (visible_ && !model_->detail_selection)
  {
    SetDetail(true, 2);
    detail_mode_ = TAB_NEXT_WINDOW;
  }

  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 134 of file SwitcherController.cpp.

{
  if (detail_on_timeout)
  {
    auto detail_timeout = std::make_shared<glib::Timeout>(detail_timeout_length);
    sources_.Add(detail_timeout, DETAIL_TIMEOUT);
    detail_timeout->Run(sigc::mem_fun(this, &Controller::OnDetailTimer));
  }

  if (icon)
  {
    if (!visible_)
    {
      ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new("(bi)", true, monitor_));
    }

    ubus_manager_.SendMessage(UBUS_SWITCHER_SELECTION_CHANGED,
                              g_variant_new_string(icon->tooltip_text().c_str()));
  }
}

Here is the call graph for this function:

Definition at line 306 of file SwitcherController.cpp.

{
  if (!model_)
    return;

  if (model_->detail_selection)
  {
    switch (detail_mode_)
    {
      case TAB_NEXT_WINDOW:
        if (model_->detail_selection_index > (unsigned int) 0)
          model_->PrevDetail();
        else
          model_->Prev();
        break;
      case TAB_NEXT_TILE:
        model_->Prev();
        break;
      case TAB_NEXT_WINDOW_LOOP:
        model_->PrevDetail(); //looping automatic
        break;
    }
  }
  else
  {
    model_->Prev();
  }
}

Here is the caller graph for this function:

Definition at line 369 of file SwitcherController.cpp.

{
  if (!model_)
    return;

  if (!model_->detail_selection)
  {
    SetDetail(true);
    detail_mode_ = TAB_NEXT_TILE;
    model_->PrevDetail();
  }
  else
  {
    model_->PrevDetail();
  }
}

Here is the call 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 SwitcherController.cpp.

{
  if (visible_)
    model_->Select(index);
}

Definition at line 416 of file SwitcherController.cpp.

{
  if (!model_)
    return;

  AbstractLauncherIcon::Ptr first  = model_->at(1);
  AbstractLauncherIcon::Ptr second = model_->at(2);

  if (!first)
  {
    model_->Select(0);
    return;
  }
  else if (!second)
  {
    model_->Select(1);
    return;
  }

  unsigned int first_highest = 0;
  unsigned int first_second = 0; // first icons second highest active
  unsigned int second_first = 0; // second icons first highest active

  for (guint32 xid : first->Windows())
  {
    unsigned int num = WindowManager::Default()->GetWindowActiveNumber(xid);

    if (num > first_highest)
    {
      first_second = first_highest;
      first_highest = num;
    }
    else if (num > first_second)
    {
      first_second = num;
    }
  }

  for (guint32 xid : second->Windows())
  {
    second_first = MAX (WindowManager::Default()->GetWindowActiveNumber(xid), second_first);
  }

  if (first_second > second_first)
    model_->Select (first);
  else
    model_->Select (second);
}

Here is the call graph for this function:

void unity::switcher::Controller::SetDetail ( bool  detail,
unsigned int  min_windows = 1 
)

Definition at line 340 of file SwitcherController.cpp.

{
  if (value && model_->DetailXids().size () >= min_windows)
  {
    model_->detail_selection = true;
    detail_mode_ = TAB_NEXT_WINDOW;
  }
  else
  {
    model_->detail_selection = false;
  }
}

Here is the caller graph for this function:

void unity::switcher::Controller::SetWorkspace ( nux::Geometry  geo,
int  monitor 
)

Definition at line 209 of file SwitcherController.cpp.

{
  monitor_ = monitor;
  workarea_ = geo;

  if (view_)
    view_->monitor = monitor_;
}

Here is the caller graph for this function:

void unity::switcher::Controller::Show ( ShowMode  show,
SortMode  sort,
bool  reverse,
std::vector< launcher::AbstractLauncherIcon::Ptr results 
)

Here is the caller graph for this function:

void unity::switcher::Controller::ShowView ( ) [protected, virtual]

Definition at line 155 of file SwitcherController.cpp.

{
  if (!visible_)
    return;

  ConstructView();

  ubus_manager_.SendMessage(UBUS_SWITCHER_START, NULL);

  if (view_window_) {
    view_window_->ShowWindow(true);
    view_window_->PushToFront();
    view_window_->SetOpacity(1.0f);
  }
}

Here is the call graph for this function:

Definition at line 272 of file SwitcherController.cpp.

{
  return visible_;
}

Member Data Documentation

Definition at line 129 of file SwitcherController.h.

Definition at line 107 of file SwitcherController.h.

Definition at line 130 of file SwitcherController.h.

Definition at line 66 of file SwitcherController.h.

Definition at line 67 of file SwitcherController.h.

Definition at line 68 of file SwitcherController.h.

Definition at line 125 of file SwitcherController.h.

Definition at line 120 of file SwitcherController.h.

Definition at line 127 of file SwitcherController.h.

Definition at line 133 of file SwitcherController.h.

Definition at line 65 of file SwitcherController.h.

Definition at line 132 of file SwitcherController.h.

Definition at line 121 of file SwitcherController.h.

nux::ObjectPtr<nux::BaseWindow> unity::switcher::Controller::view_window_ [private]

Definition at line 124 of file SwitcherController.h.

Definition at line 128 of file SwitcherController.h.

nux::Geometry unity::switcher::Controller::workarea_ [private]

Definition at line 123 of file SwitcherController.h.


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