// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2010 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Jason Smith
*/
#ifndef UNITY_POINTERWRAPPER_H
#define UNITY_POINTERWRAPPER_H
#include
#include
#include
#include
#include
namespace unity
{
namespace ui
{
struct BarrierEvent
{
typedef std::shared_ptr Ptr;
BarrierEvent(int x_, int y_, int velocity_, int event_id_)
: x(x_), y(y_), velocity(velocity_), event_id(event_id_)
{}
int x;
int y;
int velocity;
int event_id;
};
// values picked to match Xfixes values
enum BarrierDirection
{
BOTH = 0,
LEFT = 1,
UP = 2,
RIGHT = 4,
DOWN = 8
};
enum BarrierOrientation
{
VERTICAL = 0,
HORIZONTAL
};
class PointerBarrierWrapper : public sigc::trackable, public std::enable_shared_from_this
{
public:
typedef std::shared_ptr Ptr;
PointerBarrierWrapper();
virtual ~PointerBarrierWrapper();
nux::Property x1;
nux::Property x2;
nux::Property y1;
nux::Property y2;
nux::Property threshold;
nux::Property active;
nux::Property released;
nux::Property release_once;
nux::Property smoothing;
nux::Property max_velocity_multiplier;
nux::Property index;
nux::Property direction;
nux::Property orientation;
virtual void ConstructBarrier();
virtual void DestroyBarrier();
virtual void ReleaseBarrier(int event_id);
sigc::signal barrier_event;
bool IsFirstEvent() const;
bool OwnsBarrierEvent(PointerBarrier const barrier) const;
bool HandleBarrierEvent(XIBarrierEvent* barrier_event);
protected:
void EmitCurrentData(int event_id, int x, int y);
private:
void SendBarrierEvent(int x, int y, int velocity, int event_id);
int xi2_opcode_;
int last_event_;
int current_device_;
bool first_event_;
PointerBarrier barrier_;
int smoothing_count_;
int smoothing_accum_;
glib::Source::UniquePtr smoothing_timeout_;
};
}
}
#endif