Back to index

unity  6.0.0
PointerBarrier.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Jason Smith <jason.smith@canonical.com>
00018  */
00019 
00020 #ifndef UNITY_POINTERWRAPPER_H
00021 #define UNITY_POINTERWRAPPER_H
00022 
00023 #include <Nux/Nux.h>
00024 #include <X11/Xlib.h>
00025 #include <X11/extensions/Xfixes.h>
00026 #include <UnityCore/GLibSource.h>
00027 
00028 namespace unity
00029 {
00030 namespace ui
00031 {
00032 
00033 class BarrierEvent
00034 {
00035 public:
00036   typedef std::shared_ptr<BarrierEvent> Ptr;
00037 
00038   int x;
00039   int y;
00040   int velocity;
00041   int event_id;
00042 };
00043 
00044 
00045 // values picked to match Xfixes values
00046 enum BarrierDirection
00047 {
00048   BOTH = 0,
00049   LEFT = 1,
00050   RIGHT = 4,
00051 };
00052 
00053 class PointerBarrierWrapper : public sigc::trackable
00054 {
00055 public:
00056   typedef std::shared_ptr<PointerBarrierWrapper> Ptr;
00057 
00058   nux::Property<int> x1;
00059   nux::Property<int> x2;
00060   nux::Property<int> y1;
00061   nux::Property<int> y2;
00062 
00063   nux::Property<int> threshold;
00064 
00065   nux::Property<bool> active;
00066 
00067   nux::Property<int> smoothing;
00068 
00069   nux::Property<float> max_velocity_multiplier;
00070 
00071   nux::Property<int> index;
00072 
00073   nux::Property<BarrierDirection> direction;
00074 
00075   PointerBarrierWrapper();
00076   ~PointerBarrierWrapper();
00077 
00078   void ConstructBarrier();
00079   void DestroyBarrier();
00080   void ReleaseBarrier(int event_id);
00081 
00082   sigc::signal<void, PointerBarrierWrapper*, BarrierEvent::Ptr> barrier_event;
00083 
00084 private:
00085   void EmitCurrentData();
00086   bool HandleEvent (XEvent event);
00087   static bool HandleEventWrapper(XEvent event, void* data);
00088 
00089   int last_event_;
00090   int last_x_;
00091   int last_y_;
00092 
00093   int event_base_;
00094   int error_base_;
00095   PointerBarrier barrier;
00096   
00097   int smoothing_count_;
00098   int smoothing_accum_;
00099   glib::Source::UniquePtr smoothing_timeout_;
00100 };
00101 
00102 }
00103 }
00104 
00105 #endif