Back to index

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

#include <WindowButtons.h>

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

List of all members.

Public Types

typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 WindowButtons ()
void SetOpacity (double opacity)
double GetOpacity ()
void SetFocusedState (bool focused)
bool GetFocusedState ()
void SetControlledWindow (Window xid)
Window GetControlledWindow ()
void SetMonitor (int monitor)
int GetMonitor ()
virtual nux::Area * FindAreaUnderMouse (const nux::Point &mouse_pos, nux::NuxEventType event_type)
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
virtual IntrospectableList GetIntrospectableChildren ()
guint64 GetIntrospectionId () const

Public Attributes

sigc::signal< void > close_clicked
sigc::signal< void > minimize_clicked
sigc::signal< void > restore_clicked
sigc::signal< void > maximize_clicked
sigc::signal< void, int, int,
int, int, unsigned long,
unsigned long > 
mouse_move
sigc::signal< void, int, int,
unsigned long, unsigned long > 
mouse_enter
sigc::signal< void, int, int,
unsigned long, unsigned long > 
mouse_leave

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 OnCloseClicked (nux::Button *button)
void OnMinimizeClicked (nux::Button *button)
void OnRestoreClicked (nux::Button *button)
void OnMaximizeClicked (nux::Button *button)
void OnOverlayShown (GVariant *data)
void OnOverlayHidden (GVariant *data)
void OnDashSettingsUpdated ()

Private Attributes

int monitor_
double opacity_
bool focused_
Window window_xid_
std::string active_overlay_
UBusManager ubus_manager_

Detailed Description

Definition at line 32 of file WindowButtons.h.


Member Typedef Documentation

Definition at line 34 of file Introspectable.h.


Constructor & Destructor Documentation

Definition at line 337 of file WindowButtons.cpp.

  : HLayout("", NUX_TRACKER_LOCATION)
  , monitor_(0)
  , opacity_(1.0f)
  , focused_(true)
  , window_xid_(0)
{
  WindowButton* but;

  auto lambda_enter = [&](int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    mouse_enter.emit(x, y, button_flags, key_flags);
  };

  auto lambda_leave = [&](int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    mouse_leave.emit(x, y, button_flags, key_flags);
  };

  auto lambda_moved = [&](int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
  {
    mouse_move.emit(x, y, dx, dy, button_flags, key_flags);
  };

  but = new WindowButton(panel::WindowButtonType::CLOSE);
  AddView(but, 0, nux::eCenter, nux::eFix);
  AddChild(but);
  but->click.connect(sigc::mem_fun(this, &WindowButtons::OnCloseClicked));
  but->mouse_enter.connect(lambda_enter);
  but->mouse_leave.connect(lambda_leave);
  but->mouse_move.connect(lambda_moved);

  but = new WindowButton(panel::WindowButtonType::MINIMIZE);
  AddView(but, 0, nux::eCenter, nux::eFix);
  AddChild(but);
  but->click.connect(sigc::mem_fun(this, &WindowButtons::OnMinimizeClicked));
  but->mouse_enter.connect(lambda_enter);
  but->mouse_leave.connect(lambda_leave);
  but->mouse_move.connect(lambda_moved);

  but = new WindowButton(panel::WindowButtonType::UNMAXIMIZE);
  AddView(but, 0, nux::eCenter, nux::eFix);
  AddChild(but);
  but->click.connect(sigc::mem_fun(this, &WindowButtons::OnRestoreClicked));
  but->mouse_enter.connect(lambda_enter);
  but->mouse_leave.connect(lambda_leave);
  but->mouse_move.connect(lambda_moved);

  but = new WindowButton(panel::WindowButtonType::MAXIMIZE);
  AddView(but, 0, nux::eCenter, nux::eFix);
  AddChild(but);
  but->click.connect(sigc::mem_fun(this, &WindowButtons::OnMaximizeClicked));
  but->mouse_enter.connect(lambda_enter);
  but->mouse_leave.connect(lambda_leave);
  but->mouse_move.connect(lambda_moved);
  but->SetVisible(false);

  SetContentDistribution(nux::eStackLeft);

  ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, sigc::mem_fun(this, &WindowButtons::OnOverlayShown));
  ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::mem_fun(this, &WindowButtons::OnOverlayHidden));
  Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButtons::OnDashSettingsUpdated));
}

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

Implements unity::debug::Introspectable.

Definition at line 791 of file WindowButtons.cpp.

{
  variant::BuilderWrapper(builder).add(GetAbsoluteGeometry())
                                  .add("monitor", monitor_)
                                  .add("opacity", opacity_)
                                  .add("visible", opacity_ != 0.0f)
                                  .add("sensitive", GetInputEventSensitivity())
                                  .add("focused", focused_)
                                  .add("controlled_window", window_xid_);
}

Here is the call graph for this function:

nux::Area * unity::WindowButtons::FindAreaUnderMouse ( const nux::Point &  mouse_pos,
nux::NuxEventType  event_type 
) [virtual]

Definition at line 401 of file WindowButtons.cpp.

{
  /* The first button should be clickable on the left space too, to
   * make Fitts happy. All also on their top side. See bug #839690 */
  bool first_found = false;

  for (auto area : GetChildren())
  {
    if (area->IsVisible() && area->GetInputEventSensitivity())
    {
      nux::Geometry const& geo = area->GetAbsoluteGeometry();

      if (!first_found)
      {
        first_found = true;

        if (mouse.x < geo.x && mouse.y < (geo.y + geo.height))
          return area;
      }

      if (geo.IsPointInside(mouse.x, mouse.y))
        return area;

      if (mouse.x >= geo.x && mouse.x <= (geo.x + geo.width) && mouse.y <= geo.y)
        return area;
    }
  }

  return nullptr;
}
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 771 of file WindowButtons.cpp.

{
  return window_xid_;
}

Definition at line 735 of file WindowButtons.cpp.

{
  return focused_;
}
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:

Definition at line 781 of file WindowButtons.cpp.

{
  return monitor_;
}
std::string unity::WindowButtons::GetName ( ) const [protected, virtual]

Implements unity::debug::Introspectable.

Definition at line 786 of file WindowButtons.cpp.

{
  return "WindowButtons";
}

Definition at line 713 of file WindowButtons.cpp.

{
  return opacity_;
}
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:

void unity::WindowButtons::OnCloseClicked ( nux::Button *  button) [private]

Definition at line 432 of file WindowButtons.cpp.

{
  auto win_button = dynamic_cast<WindowButton*>(button);

  if (!win_button || !win_button->IsEnabled())
    return;

  if (win_button->IsOverlayOpen())
  {
    ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
  }
  else
  {
    WindowManager::Default()->Close(window_xid_);
  }

  close_clicked.emit();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 648 of file WindowButtons.cpp.

{
  WindowButton* maximize_button = nullptr;
  WindowButton* restore_button = nullptr;

  for (auto area : GetChildren())
  {
    auto button = dynamic_cast<WindowButton*>(area);

    if (button)
    {
      if (!button->IsOverlayOpen())
        break;

      if (button->GetType() == panel::WindowButtonType::UNMAXIMIZE)
        restore_button = button;

      if (button->GetType() == panel::WindowButtonType::MAXIMIZE)
        maximize_button = button;

      if (restore_button && maximize_button)
        break;
    }
  }

  if (restore_button && restore_button->IsOverlayOpen() && maximize_button)
  {
    Settings &dash_settings = Settings::Instance();
    bool maximizable = (dash_settings.GetFormFactor() == FormFactor::DESKTOP);

    if (maximizable != maximize_button->IsVisible())
    {
      if (maximize_button->IsVisible())
        restore_button->SetVisualState(maximize_button->GetVisualState());
      else if (restore_button->IsVisible())
        maximize_button->SetVisualState(restore_button->GetVisualState());

      restore_button->SetVisible(!maximizable);
      maximize_button->SetVisible(maximizable);

      QueueRelayout();
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::WindowButtons::OnMaximizeClicked ( nux::Button *  button) [private]

Definition at line 488 of file WindowButtons.cpp.

{
  auto win_button = dynamic_cast<WindowButton*>(button);

  if (!win_button || !win_button->IsEnabled())
    return;

  if (win_button->IsOverlayOpen())
  {
    Settings::Instance().SetFormFactor(FormFactor::NETBOOK);
  }

  maximize_clicked.emit();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::WindowButtons::OnMinimizeClicked ( nux::Button *  button) [private]

Definition at line 451 of file WindowButtons.cpp.

{
  auto win_button = dynamic_cast<WindowButton*>(button);

  if (!win_button || !win_button->IsEnabled())
    return;

  if (!win_button->IsOverlayOpen())
    WindowManager::Default()->Minimize(window_xid_);

  minimize_clicked.emit();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::WindowButtons::OnOverlayHidden ( GVariant *  data) [private]

Definition at line 573 of file WindowButtons.cpp.

{
  WindowButton* maximize_button = nullptr;
  WindowButton* restore_button = nullptr;

  glib::String overlay_identity;
  gboolean can_maximise = FALSE;
  gint32 overlay_monitor = 0;
  g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING,
                &overlay_identity, &can_maximise, &overlay_monitor);

  if (overlay_monitor != monitor_)
  {
    for (auto area : GetChildren())
    {
      auto button = dynamic_cast<WindowButton*>(area);

      if (button)
        button->SetEnabled(true);
    }
  }

  if (active_overlay_ != overlay_identity.Str())
    return;

  active_overlay_ = "";

  for (auto area : GetChildren())
  {
    auto button = dynamic_cast<WindowButton*>(area);

    if (button)
    {
      if (window_xid_)
      {
        if (button->GetType() == panel::WindowButtonType::CLOSE)
        {
          bool closable = WindowManager::Default()->IsWindowClosable(window_xid_);
          button->SetEnabled(closable);
        }

        if (button->GetType() == panel::WindowButtonType::MINIMIZE)
        {
          bool minimizable = WindowManager::Default()->IsWindowMinimizable(window_xid_);
          button->SetEnabled(minimizable);
        }
      }

      if (button->GetType() == panel::WindowButtonType::UNMAXIMIZE)
        restore_button = button;

      if (button->GetType() == panel::WindowButtonType::MAXIMIZE)
        maximize_button = button;

      button->SetOverlayOpen(false);
    }
  }

  if (restore_button && maximize_button)
  {
    restore_button->SetEnabled(true);
    maximize_button->SetEnabled(true);

    if (!restore_button->IsVisible())
    {
      restore_button->SetVisualState(maximize_button->GetVisualState());

      restore_button->SetVisible(true);
      maximize_button->SetVisible(false);

      QueueDraw();
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::WindowButtons::OnOverlayShown ( GVariant *  data) [private]

Definition at line 503 of file WindowButtons.cpp.

{
  WindowButton* maximize_button = nullptr;
  WindowButton* restore_button = nullptr;
  glib::String overlay_identity;
  gboolean can_maximise = FALSE;
  gint32 overlay_monitor = 0;
  g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING,
                &overlay_identity, &can_maximise, &overlay_monitor);

  if (overlay_monitor != monitor_)
  {
    for (auto area : GetChildren())
    {
      auto button = dynamic_cast<WindowButton*>(area);

      if (button)
        button->SetEnabled(false);
    }

    return;
  }

  active_overlay_ = overlay_identity.Str();

  for (auto area : GetChildren())
  {
    auto button = dynamic_cast<WindowButton*>(area);

    if (button)
    {
      if (button->GetType() == panel::WindowButtonType::CLOSE)
        button->SetEnabled(true);

      if (button->GetType() == panel::WindowButtonType::UNMAXIMIZE)
        restore_button = button;

      if (button->GetType() == panel::WindowButtonType::MAXIMIZE)
        maximize_button = button;

      if (button->GetType() == panel::WindowButtonType::MINIMIZE)
        button->SetEnabled(false);

      button->SetOverlayOpen(true);
    }
  }

  if (restore_button && maximize_button)
  {
    Settings &dash_settings = Settings::Instance();
    bool maximizable = (dash_settings.GetFormFactor() == FormFactor::DESKTOP);

    restore_button->SetEnabled(can_maximise);
    maximize_button->SetEnabled(can_maximise);

    if (maximizable != maximize_button->IsVisible())
    {
      if (maximize_button->IsVisible())
        restore_button->SetVisualState(maximize_button->GetVisualState());
      else if (restore_button->IsVisible())
        maximize_button->SetVisualState(restore_button->GetVisualState());

      restore_button->SetVisible(!maximizable);
      maximize_button->SetVisible(maximizable);

      QueueDraw();
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::WindowButtons::OnRestoreClicked ( nux::Button *  button) [private]

Definition at line 464 of file WindowButtons.cpp.

{
  auto win_button = dynamic_cast<WindowButton*>(button);

  if (!win_button || !win_button->IsEnabled())
    return;

  if (win_button->IsOverlayOpen())
  {
    Settings::Instance().SetFormFactor(FormFactor::DESKTOP);
  }
  else
  {
    WindowManager* wm = WindowManager::Default();
    Window to_restore = window_xid_;

    wm->Raise(to_restore);
    wm->Activate(to_restore);
    wm->Restore(to_restore);
  }

  restore_clicked.emit();
}

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 740 of file WindowButtons.cpp.

{
  if (xid != window_xid_)
  {
    window_xid_ = xid;

    if (window_xid_ && active_overlay_.empty())
    {
      for (auto area : GetChildren())
      {
        auto button = dynamic_cast<WindowButton*>(area);

        if (!button)
          continue;

        if (button->GetType() == panel::WindowButtonType::CLOSE)
        {
          bool closable = WindowManager::Default()->IsWindowClosable(xid);
          button->SetEnabled(closable);
        }

        if (button->GetType() == panel::WindowButtonType::MINIMIZE)
        {
          bool minimizable = WindowManager::Default()->IsWindowMinimizable(xid);
          button->SetEnabled(minimizable);
        }
      }
    }
  }
}

Here is the call graph for this function:

void unity::WindowButtons::SetFocusedState ( bool  focused)

Definition at line 718 of file WindowButtons.cpp.

{
  for (auto area : GetChildren())
  {
    auto button = dynamic_cast<WindowButton*>(area);

    if (button)
      button->SetFocusedState(focused);
  }

  if (focused_ != focused)
  {
    focused_ = focused;
    QueueDraw();
  }
}

Here is the call graph for this function:

void unity::WindowButtons::SetMonitor ( int  monitor)

Definition at line 776 of file WindowButtons.cpp.

{
  monitor_ = monitor;
}
void unity::WindowButtons::SetOpacity ( double  opacity)

Definition at line 693 of file WindowButtons.cpp.

{
  opacity = CLAMP(opacity, 0.0f, 1.0f);

  for (auto area : GetChildren())
  {
    auto button = dynamic_cast<WindowButton*>(area);

    if (button)
      button->SetOpacity(opacity);
  }

  if (opacity_ != opacity)
  {
    opacity_ = opacity;
    SetInputEventSensitivity(opacity_ != 0.0f);
    QueueDraw();
  }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 79 of file WindowButtons.h.

Definition at line 54 of file WindowButtons.h.

Definition at line 77 of file WindowButtons.h.

Definition at line 57 of file WindowButtons.h.

Definition at line 55 of file WindowButtons.h.

Definition at line 75 of file WindowButtons.h.

sigc::signal<void, int, int, unsigned long, unsigned long> unity::WindowButtons::mouse_enter

Definition at line 59 of file WindowButtons.h.

sigc::signal<void, int, int, unsigned long, unsigned long> unity::WindowButtons::mouse_leave

Definition at line 60 of file WindowButtons.h.

sigc::signal<void, int, int, int, int, unsigned long, unsigned long> unity::WindowButtons::mouse_move

Definition at line 58 of file WindowButtons.h.

Definition at line 76 of file WindowButtons.h.

Definition at line 56 of file WindowButtons.h.

Definition at line 81 of file WindowButtons.h.

Definition at line 78 of file WindowButtons.h.


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