Ejemplo n.º 1
0
EdgeBarrierController::Impl::Impl(EdgeBarrierController *parent)
  : xi2_opcode_(-1)
  , edge_overcome_pressure_(0)
  , parent_(parent)
{
  UScreen *uscreen = UScreen::GetDefault();

  auto monitors = uscreen->GetMonitors();
  ResizeBarrierList(monitors);

  /* FIXME: Back to c++11 lambda once we get sigc::track_obj.
  uscreen->changed.connect(sigc::track_obj(([this](int primary, std::vector<nux::Geometry> const& layout) {
    ResizeBarrierList(layout);
    SetupBarriers(layout);
  }));*/

  uscreen->changed.connect(sigc::mem_fun(this, &EdgeBarrierController::Impl::OnUScreenChanged));

  parent_->force_disable.changed.connect([this] (bool) {
    auto monitors = UScreen::GetDefault()->GetMonitors();
    ResizeBarrierList(monitors);
    SetupBarriers(monitors);
  });

  parent_->sticky_edges.SetGetterFunction([this] {
    return parent_->options() ? parent_->options()->edge_resist() : false;
  });

  parent_->sticky_edges.SetSetterFunction([this] (bool const& new_val) {
    if (parent_->options() && new_val != parent_->options()->edge_resist())
    {
      parent_->options()->edge_resist = new_val;
      return true;
    }
    return false;
  });

  parent_->options.changed.connect([this](launcher::Options::Ptr options) {
    /* FIXME: Back to c++11 lambda once we get sigc::track_obj.
    options->option_changed.connect([this]() {
      SetupBarriers(UScreen::GetDefault()->GetMonitors());
    });*/
    options->option_changed.connect(sigc::mem_fun(this, &EdgeBarrierController::Impl::OnOptionsChanged));
    SetupBarriers(UScreen::GetDefault()->GetMonitors());
  });

  xi2_opcode_ = GetXI2OpCode();
}
void EdgeBarrierController::Impl::RemoveSubscriber(EdgeBarrierSubscriber* subscriber, unsigned int monitor, std::vector<EdgeBarrierSubscriber*>& subscribers)
{
  if (monitor >= subscribers.size() || subscribers[monitor] != subscriber)
    return;

  auto const& monitors = UScreen::GetDefault()->GetMonitors();
  subscribers[monitor] = nullptr;
  ResizeBarrierList(monitors);
  SetupBarriers(monitors);
}
void EdgeBarrierController::Impl::AddSubscriber(EdgeBarrierSubscriber* subscriber, unsigned int monitor, std::vector<EdgeBarrierSubscriber*>& subscribers)
{
  if (monitor >= subscribers.size())
    subscribers.resize(monitor + 1);

  auto const& monitors = UScreen::GetDefault()->GetMonitors();
  subscribers[monitor] = subscriber;
  ResizeBarrierList(monitors);
  SetupBarriers(monitors);
}
void EdgeBarrierController::Impl::OnUScreenChanged(int primary, std::vector<nux::Geometry> const& layout)
{
  ResizeBarrierList(layout);
  SetupBarriers(layout);
}