Back to index

unity  6.0.0
unity-mt-grab-handles.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
00017  */
00018 
00019 #include <Nux/Nux.h>
00020 #include <glib.h>
00021 #include <core/core.h>
00022 #include <composite/composite.h>
00023 #include <opengl/opengl.h>
00024 #include <boost/noncopyable.hpp>
00025 #include <boost/shared_ptr.hpp>
00026 #include <boost/enable_shared_from_this.hpp>
00027 #include <boost/weak_ptr.hpp>
00028 
00029 #include <core/atoms.h>
00030 
00031 #include "unity-mt-texture.h"
00032 #include "unity-mt-grab-handle.h"
00033 #include "unity-mt-grab-handle-group.h"
00034 #include "unity-mt-grab-handle-window.h"
00035 #include "unity-mt-grab-handle-impl-factory.h"
00036 #include "unity-mt-grab-handle-layout.h"
00037 
00038 #include "unitymtgrabhandles_options.h"
00039 
00040 namespace unity
00041 {
00042 namespace MT
00043 {
00044 
00045 class DummyDamager
00046 {
00047 public:
00048 
00049     void damage (const nux::Geometry &g)
00050     {
00051       std::cout << "Damage rects: " << std::endl;
00052       std::cout << "x: " << g.x << " y: " << g.y << " width: " << g.width << " height: " << g.height << std::endl;
00053     }
00054 };
00055 
00056 class X11TextureFactory :
00057   public Texture::Factory
00058 {
00059   public:
00060 
00061     void setActiveWrap (const GLTexture::List &);
00062 
00063     Texture::Ptr create ();
00064 
00065   private:
00066 
00067     GLTexture::List mWrap;
00068 };
00069 
00070 class X11Texture :
00071   public Texture
00072 {
00073   public:
00074 
00075     typedef boost::shared_ptr <X11Texture> Ptr;
00076 
00077     X11Texture (const GLTexture::List &t);
00078 
00079     const GLTexture::List & get ();
00080 
00081   private:
00082 
00083     GLTexture::List mTexture;
00084 };
00085 
00086 class X11ImplFactory :
00087   public GrabHandle::ImplFactory
00088 {
00089   public:
00090 
00091     X11ImplFactory (Display *dpy);
00092 
00093     GrabHandle::Impl * create (const GrabHandle::Ptr &h);
00094   private:
00095     Display *mDpy;
00096 };
00097 
00098 class X11GrabHandleImpl :
00099   public GrabHandle::Impl
00100 {
00101 public:
00102 
00103   X11GrabHandleImpl (Display *dpy, const GrabHandle::Ptr &h);
00104   ~X11GrabHandleImpl ();
00105 
00106 public:
00107 
00108   void show ();
00109   void hide ();
00110 
00111   void buttonPress (int x,
00112                     int y,
00113                     unsigned int button) const;
00114 
00115   void lockPosition (int x,
00116                      int y,
00117                      unsigned int flags);
00118 
00119   void damage (const nux::Geometry &g)
00120   {
00121     CompRegion r (g.x, g.y, g.width, g.height);
00122     CompositeScreen::get (screen)->damageRegion (r);
00123   }
00124 
00125 private:
00126 
00127   boost::weak_ptr <unity::MT::GrabHandle>  mGrabHandle;
00128   Window                                   mIpw;
00129   Display                                  *mDpy;
00130 };
00131 
00132 };
00133 };
00134 
00135 class UnityMTGrabHandlesScreen :
00136   public PluginClassHandler <UnityMTGrabHandlesScreen, CompScreen>,
00137   public ScreenInterface,
00138   public CompositeScreenInterface,
00139   public GLScreenInterface,
00140   public UnitymtgrabhandlesOptions
00141 {
00142 public:
00143 
00144   UnityMTGrabHandlesScreen(CompScreen*);
00145   ~UnityMTGrabHandlesScreen();
00146 
00147   CompositeScreen* cScreen;
00148   GLScreen*  gScreen;
00149 
00150 public:
00151 
00152   void handleEvent(XEvent*);
00153 
00154   bool toggleHandles(CompAction*         action,
00155                      CompAction::State  state,
00156                      CompOption::Vector& options);
00157 
00158   bool showHandles(CompAction*         action,
00159                    CompAction::State  state,
00160                    CompOption::Vector& options);
00161 
00162   bool hideHandles(CompAction*         action,
00163                    CompAction::State  state,
00164                    CompOption::Vector& options);
00165 
00166   void optionChanged (CompOption *option,
00167                       UnitymtgrabhandlesOptions::Options num);
00168 
00169   void addHandles(const unity::MT::GrabHandleGroup::Ptr & handles);
00170   void removeHandles(const unity::MT::GrabHandleGroup::Ptr & handles);
00171 
00172   void addHandleWindow(const unity::MT::GrabHandle::Ptr &, Window);
00173   void removeHandleWindow(Window);
00174 
00175   void preparePaint(int);
00176   void donePaint();
00177 
00178   void raiseHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &,
00179                     Window                      owner);
00180 
00181   std::vector <unity::MT::TextureSize>  & textures()
00182   {
00183     return mHandleTextures;
00184   }
00185 
00186 private:
00187 
00188   std::list <unity::MT::GrabHandleGroup::Ptr> mGrabHandles;
00189   std::vector <unity::MT::TextureSize> mHandleTextures;
00190 
00191   std::map <Window, const unity::MT::GrabHandle::Ptr> mInputHandles;
00192   CompWindowVector                     mLastClientListStacking;
00193   Atom                                 mCompResizeWindowAtom;
00194 
00195   bool          mMoreAnimate;
00196 };
00197 
00198 #define UMTGH_SCREEN(screen)                  \
00199     UnityMTGrabHandlesScreen *us = UnityMTGrabHandlesScreen::get (screen)
00200 
00201 class UnityMTGrabHandlesWindow :
00202   public PluginClassHandler <UnityMTGrabHandlesWindow, CompWindow>,
00203   public WindowInterface,
00204   public CompositeWindowInterface,
00205   public GLWindowInterface,
00206   public unity::MT::GrabHandleWindow
00207 {
00208 public:
00209 
00210   UnityMTGrabHandlesWindow(CompWindow*);
00211   ~UnityMTGrabHandlesWindow();
00212 
00213   CompWindow*  window;
00214   CompositeWindow* cWindow;
00215   GLWindow*  gWindow;
00216 
00217 public:
00218 
00219   bool allowHandles();
00220   bool handleTimerActive();
00221 
00222   void grabNotify(int, int, unsigned int, unsigned int);
00223   void ungrabNotify();
00224 
00225   void relayout(const CompRect&, bool);
00226 
00227   void getOutputExtents(CompWindowExtents& output);
00228 
00229   void moveNotify(int dx, int dy, bool immediate);
00230 
00231   bool glDraw(const GLMatrix&,
00232 #ifdef USE_MODERN_COMPIZ_GL
00233               const GLWindowPaintAttrib&,
00234 #else
00235               GLFragment::Attrib&,
00236 #endif
00237               const CompRegion&,
00238               unsigned int);
00239 
00240   bool    handlesVisible();
00241   void    hideHandles();
00242   void    showHandles(bool use_timer);
00243   void    restackHandles();
00244 
00245   void resetTimer();
00246   void disableTimer();
00247 
00248 protected:
00249 
00250   void raiseGrabHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &h);
00251   void requestMovement (int x,
00252                         int y,
00253                         unsigned int direction,
00254                      unsigned int button);
00255 
00256 private:
00257 
00258   bool onHideTimeout();
00259 
00260   unity::MT::GrabHandleGroup::Ptr mHandles;
00261   CompTimer                       mTimer;
00262 };
00263 
00264 #define UMTGH_WINDOW(window)                  \
00265     UnityMTGrabHandlesWindow *uw = UnityMTGrabHandlesWindow::get (window)
00266 
00267 class UnityMTGrabHandlesPluginVTable :
00268   public CompPlugin::VTableForScreenAndWindow < UnityMTGrabHandlesScreen,
00269   UnityMTGrabHandlesWindow >
00270 {
00271 public:
00272 
00273   bool init();
00274 };