Back to index

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

#include <HudController.h>

Inheritance diagram for unity::hud::Controller:
Inheritance graph
[legend]
Collaboration diagram for unity::hud::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 (std::function< AbstractView *(void)> const &function=[](){return new View;})
nux::BaseWindow * window () const
void ShowHideHud ()
void ShowHud ()
void HideHud (bool restore_focus=true)
bool IsVisible ()
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
virtual IntrospectableList GetIntrospectableChildren ()
guint64 GetIntrospectionId () const

Public Attributes

nux::Property< int > launcher_width
nux::Property< int > icon_size
nux::Property< int > tile_size
nux::Property< bool > launcher_locked_out
nux::Property< bool > multiple_launchers

Protected Member Functions

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

void EnsureHud ()
void SetupWindow ()
void SetupHudView ()
void RegisterUBusInterests ()
void SetIcon (std::string const &icon_name)
int GetTargetMonitor ()
bool IsLockedToLauncher (int monitor)
nux::Geometry GetIdealWindowGeometry ()
void Relayout ()
void OnMouseDownOutsideWindow (int x, int y, unsigned long bflags, unsigned long kflags)
void OnScreenUngrabbed ()
void OnExternalShowHud (GVariant *variant)
void OnExternalHideHud (GVariant *variant)
void OnActivateRequest (GVariant *variant)
void OnSearchChanged (std::string search_string)
void OnSearchActivated (std::string search_string)
void OnQueryActivated (Query::Ptr query)
void OnQuerySelected (Query::Ptr query)
void StartShowHideTimeline ()
void OnViewShowHideFrame (double progress)
void OnQueriesFinished (Hud::Queries queries)

Static Private Member Functions

static void OnWindowConfigure (int width, int height, nux::Geometry &geo, void *data)

Private Attributes

nux::ObjectPtr< nux::BaseWindow > window_
UBusManager ubus
Hud hud_service_
bool visible_
bool need_show_
Animator timeline_animator_
AbstractViewview_
std::string focused_app_icon_
nux::Layout * layout_
uint monitor_index_
std::string last_search_
std::function< AbstractView
*(void)> 
view_function_

Detailed Description

Definition at line 42 of file HudController.h.


Member Typedef Documentation

Definition at line 34 of file Introspectable.h.

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

Definition at line 45 of file HudController.h.


Constructor & Destructor Documentation


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

Implements unity::debug::Introspectable.

Definition at line 486 of file HudController.cpp.

{
  variant::BuilderWrapper(builder)
    .add(window_ ? window_->GetGeometry() : nux::Geometry())
    .add("visible", visible_)
    .add("hud_monitor", monitor_index_)
    .add("locked_to_launcher", IsLockedToLauncher(monitor_index_));
}

Here is the call graph for this function:

Definition at line 145 of file HudController.cpp.

{
  LOG_DEBUG(logger) << "Initializing Hud";

  if (!window_)
    SetupWindow();

  if (!view_)
  {
    SetupHudView();
    Relayout();
  }
}

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:

Definition at line 182 of file HudController.cpp.

{
  int target_monitor = GetTargetMonitor();
  auto monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(target_monitor);

  // We want to cover as much of the screen as possible to grab any mouse events
  // outside of our window
  panel::Style &panel_style = panel::Style::Instance();
  nux::Geometry geo(monitor_geo.x,
                    monitor_geo.y + panel_style.panel_height,
                    monitor_geo.width,
                    monitor_geo.height - panel_style.panel_height);

  if (IsLockedToLauncher(target_monitor))
  {
    geo.x += launcher_width;
    geo.width -= launcher_width;
  }

  return geo;
}

Here is the call graph for this function:

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::hud::Controller::GetName ( ) const [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 481 of file HudController.cpp.

{
  return "HudController";
}

Definition at line 125 of file HudController.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::hud::Controller::HideHud ( bool  restore_focus = true)

Definition at line 367 of file HudController.cpp.

{
  LOG_DEBUG (logger) << "hiding the hud";
  if (visible_ == false)
    return;

  need_show_ = false;
  EnsureHud();
  view_->AboutToHide();
  window_->CaptureMouseDownAnyWhereElse(false);
  window_->EnableInputWindow(false, "Hud", true, false);
  visible_ = false;

  nux::GetWindowCompositor().SetKeyFocusArea(NULL,nux::KEY_NAV_NONE);

  StartShowHideTimeline();

  restore = true;
  if (restore)
    WindowManager::Default ()->restoreInputFocus ();

  hud_service_.CloseQuery();

  //unhide the launcher
  GVariant* message_data = g_variant_new("(b)", FALSE);
  ubus.SendMessage(UBUS_LAUNCHER_LOCK_HIDE, message_data);

  GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "hud", FALSE, monitor_index_);
  ubus.SendMessage(UBUS_OVERLAY_HIDDEN, info);
}

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:

bool unity::hud::Controller::IsLockedToLauncher ( int  monitor) [private]

Definition at line 130 of file HudController.cpp.

{
  if (launcher_locked_out)
  {
    int primary_monitor = UScreen::GetDefault()->GetPrimaryMonitor();

    if (multiple_launchers || (!multiple_launchers && primary_monitor == monitor))
    {
      return true;
    }
  }

  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 256 of file HudController.cpp.

{
  return visible_;
}
void unity::hud::Controller::OnActivateRequest ( GVariant *  variant) [private]

Definition at line 426 of file HudController.cpp.

{
  EnsureHud();
  ShowHud();
}

Here is the call graph for this function:

void unity::hud::Controller::OnExternalHideHud ( GVariant *  variant) [private]

Definition at line 243 of file HudController.cpp.

{
  LOG_DEBUG(logger) << "External Hiding the hud";
  EnsureHud();
  HideHud();
}

Here is the call graph for this function:

void unity::hud::Controller::OnExternalShowHud ( GVariant *  variant) [private]

Definition at line 237 of file HudController.cpp.

Here is the call graph for this function:

void unity::hud::Controller::OnMouseDownOutsideWindow ( int  x,
int  y,
unsigned long  bflags,
unsigned long  kflags 
) [private]

Definition at line 216 of file HudController.cpp.

{
  LOG_DEBUG(logger) << "OnMouseDownOutsideWindow called";
  HideHud();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 463 of file HudController.cpp.

{
  view_->SetQueries(queries);
  std::string icon_name = focused_app_icon_;
  for (auto query = queries.begin(); query != queries.end(); query++)
  {
    if (!(*query)->icon_name.empty())
    {
      icon_name = (*query)->icon_name;
      break;
    }
  }

  SetIcon(icon_name);
  view_->SearchFinished();
}

Here is the call graph for this function:

Definition at line 449 of file HudController.cpp.

{
  LOG_DEBUG(logger) << "Activating query, " << query->formatted_text;
  unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp;
  hud_service_.ExecuteQuery(query, timestamp);
  ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 457 of file HudController.cpp.

{
  LOG_DEBUG(logger) << "Selected query, " << query->formatted_text;
  SetIcon(query->icon_name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 223 of file HudController.cpp.

{
  LOG_DEBUG(logger) << "OnScreenUngrabbed called";
  if (need_show_)
  {
    nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus());

    window_->PushToFront();
    window_->SetInputFocus();
    EnsureHud();
    ShowHud();
  }
}

Here is the call graph for this function:

void unity::hud::Controller::OnSearchActivated ( std::string  search_string) [private]

Definition at line 442 of file HudController.cpp.

{
  unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp;
  hud_service_.ExecuteQueryBySearch(search_string, timestamp);
  ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::hud::Controller::OnSearchChanged ( std::string  search_string) [private]

Definition at line 432 of file HudController.cpp.

{
  // we're using live_search_reached, so this is called 40ms after the text
  // is input in the search bar
  LOG_DEBUG(logger) << "Search Changed";

  last_search_ = search_string;
  hud_service_.RequestQuery(last_search_);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::hud::Controller::OnViewShowHideFrame ( double  progress) [private]

Definition at line 407 of file HudController.cpp.

{
  window_->SetOpacity(visible_ ? progress : 1.0f - progress);

  if (progress == 1.0f)
  {
    if (!visible_)
    {
      window_->ShowWindow(false);
      view_->ResetToDefault();
    }
    else
    {
      // ensure the text entry is focused
      nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus());
    }
  }
}

Here is the call graph for this function:

void unity::hud::Controller::OnWindowConfigure ( int  width,
int  height,
nux::Geometry &  geo,
void *  data 
) [static, private]

Definition at line 175 of file HudController.cpp.

{
  Controller* self = static_cast<Controller*>(data);
  geo = self->GetIdealWindowGeometry();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 204 of file HudController.cpp.

{
  EnsureHud();
  nux::Geometry const& content_geo = view_->GetGeometry();
  nux::Geometry const& geo = GetIdealWindowGeometry();

  window_->SetGeometry(geo);
  layout_->SetMinMaxSize(content_geo.width, content_geo.height);
  view_->SetWindowGeometry(window_->GetAbsoluteGeometry(), window_->GetGeometry());
  view_->Relayout();
}

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:

void unity::hud::Controller::SetIcon ( std::string const &  icon_name) [private]

Definition at line 159 of file HudController.cpp.

{
  LOG_DEBUG(logger) << "setting icon to - " << icon_name;

  if (view_)
    view_->SetIcon(icon_name, tile_size, icon_size, launcher_width - tile_size);

  ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(icon_name.c_str()));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 105 of file HudController.cpp.

{
  LOG_DEBUG(logger) << "SetupHudView called";
  view_ = view_function_();

  layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
  layout_->AddView(view_, 1, nux::MINOR_POSITION_TOP);
  window_->SetLayout(layout_);

  view_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow));

  LOG_DEBUG(logger) << "connecting to signals";
  view_->search_changed.connect(sigc::mem_fun(this, &Controller::OnSearchChanged));
  view_->search_activated.connect(sigc::mem_fun(this, &Controller::OnSearchActivated));
  view_->query_activated.connect(sigc::mem_fun(this, &Controller::OnQueryActivated));
  view_->query_selected.connect(sigc::mem_fun(this, &Controller::OnQuerySelected));
  // Add to the debug introspection.
  AddChild(view_);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 88 of file HudController.cpp.

{
  window_.Adopt(new nux::BaseWindow("Hud"));
  window_->SetBackgroundColor(nux::Color(0.0f, 0.0f, 0.0f, 0.0f));
  window_->SetConfigureNotifyCallback(&Controller::OnWindowConfigure, this);
  window_->ShowWindow(false);
  window_->SetOpacity(0.0f);
  window_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow));
  
  /* FIXME - first time we load our windows there is a race that causes the input window not to actually get input, this side steps that by causing an input window show and hide before we really need it. */
  auto wm = WindowManager::Default();
  wm->saveInputFocus ();
  window_->EnableInputWindow(true, "Hud", true, false);
  window_->EnableInputWindow(false, "Hud", true, false);
  wm->restoreInputFocus ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 250 of file HudController.cpp.

{
  EnsureHud();
  visible_ ? HideHud(true) : ShowHud();
}

Here is the call graph for this function:

Definition at line 261 of file HudController.cpp.

{
  WindowManager* adaptor = WindowManager::Default();
  LOG_DEBUG(logger) << "Showing the hud";
  EnsureHud();

  if (visible_ || adaptor->IsExpoActive() || adaptor->IsScaleActive())
   return;

  if (adaptor->IsScreenGrabbed())
  {
    need_show_ = true;
    return;
  }

  unsigned int target_monitor = GetTargetMonitor();

  if (target_monitor != monitor_index_)
  {
    Relayout();
    monitor_index_ = target_monitor;
  }

  view_->ShowEmbeddedIcon(!IsLockedToLauncher(monitor_index_));
  view_->AboutToShow();

  // We first want to grab the currently active window
  glib::Object<BamfMatcher> matcher(bamf_matcher_get_default());
  BamfWindow* active_win = bamf_matcher_get_active_window(matcher);

  Window active_xid = bamf_window_get_xid(active_win);
  std::vector<Window> const& unity_xids = nux::XInputWindow::NativeHandleList();

  // If the active window is an unity window, we must get the top-most valid window
  if (std::find(unity_xids.begin(), unity_xids.end(), active_xid) != unity_xids.end())
  {
    // Windows list stack for all the monitors
    GList *windows = bamf_matcher_get_window_stack_for_monitor(matcher, -1);

    // Reset values, in case we can't find a window ie. empty current desktop
    active_xid = 0;
    active_win = nullptr;

    for (GList *l = windows; l; l = l->next)
    {
      if (!BAMF_IS_WINDOW(l->data))
        continue;

      auto win = static_cast<BamfWindow*>(l->data);
      auto view = static_cast<BamfView*>(l->data);
      Window xid = bamf_window_get_xid(win);

      if (bamf_view_user_visible(view) && bamf_window_get_window_type(win) != BAMF_WINDOW_DOCK &&
          WindowManager::Default()->IsWindowOnCurrentDesktop(xid) &&
          WindowManager::Default()->IsWindowVisible(xid) &&
          std::find(unity_xids.begin(), unity_xids.end(), xid) == unity_xids.end())
      {
        active_win = win;
        active_xid = xid;
      }
    }

    g_list_free(windows);
  }

  BamfApplication* active_app = bamf_matcher_get_application_for_window(matcher, active_win);

  if (BAMF_IS_VIEW(active_app))
  {
    auto active_view = reinterpret_cast<BamfView*>(active_app);
    glib::String view_icon(bamf_view_get_icon(active_view));
    focused_app_icon_ = view_icon.Str();
  }
  else
  {
    focused_app_icon_ = focused_app_icon_ = PKGDATADIR "/launcher_bfb.png";
  }

  LOG_DEBUG(logger) << "Taking application icon: " << focused_app_icon_;
  SetIcon(focused_app_icon_);

  window_->ShowWindow(true);
  window_->PushToFront();
  window_->EnableInputWindow(true, "Hud", true, false);
  window_->SetInputFocus();
  window_->CaptureMouseDownAnyWhereElse(true);
  view_->CaptureMouseDownAnyWhereElse(true);
  window_->QueueDraw();

  view_->ResetToDefault();
  need_show_ = true;
  visible_ = true;

  StartShowHideTimeline();
  view_->SetWindowGeometry(window_->GetAbsoluteGeometry(), window_->GetGeometry());

  // hide the launcher
  GVariant* message_data = g_variant_new("(b)", TRUE);
  ubus.SendMessage(UBUS_LAUNCHER_LOCK_HIDE, message_data);
  GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "hud", FALSE, monitor_index_);
  ubus.SendMessage(UBUS_OVERLAY_SHOWN, info);

  nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus());
  window_->SetEnterFocusInputArea(view_->default_focus());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 398 of file HudController.cpp.

{
  EnsureHud();

  double current_opacity = window_->GetOpacity();
  timeline_animator_.Stop();
  timeline_animator_.Start(visible_ ? current_opacity : 1.0f - current_opacity);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nux::BaseWindow * unity::hud::Controller::window ( ) const

Definition at line 169 of file HudController.cpp.

{
  return window_.GetPointer();
}

Member Data Documentation

Definition at line 108 of file HudController.h.

Definition at line 101 of file HudController.h.

Definition at line 52 of file HudController.h.

std::string unity::hud::Controller::last_search_ [private]

Definition at line 111 of file HudController.h.

Definition at line 54 of file HudController.h.

Definition at line 51 of file HudController.h.

nux::Layout* unity::hud::Controller::layout_ [private]

Definition at line 109 of file HudController.h.

Definition at line 110 of file HudController.h.

Definition at line 55 of file HudController.h.

Definition at line 103 of file HudController.h.

Definition at line 53 of file HudController.h.

Definition at line 105 of file HudController.h.

Definition at line 100 of file HudController.h.

Definition at line 107 of file HudController.h.

std::function<AbstractView*(void)> unity::hud::Controller::view_function_ [private]

Definition at line 113 of file HudController.h.

Definition at line 102 of file HudController.h.

nux::ObjectPtr<nux::BaseWindow> unity::hud::Controller::window_ [private]

Definition at line 99 of file HudController.h.


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