Back to index

unity  6.0.0
unitydialog.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 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 <gtk/gtk.h>
00020 #include <core/core.h>
00021 #include <core/atoms.h>
00022 #include <composite/composite.h>
00023 #include <opengl/opengl.h>
00024 #include <X11/Xatom.h>
00025 #include <X11/Xproto.h>
00026 
00027 #include <cairo-xlib-xrender.h>
00028 
00029 #include "unitydialog_options.h"
00030 
00031 namespace unity
00032 {
00033   typedef std::vector <GLTexture::MatrixList> MatrixListVector;
00034   typedef std::vector <CompRegion> CompRegionVector;
00035   typedef std::vector <int> IntVector;
00036 
00037   class GeometryCollection
00038   {
00039     public:
00040       GeometryCollection ();
00041       bool status ();
00042 
00043       void addGeometryForWindow (CompWindow *, const CompRegion &paintRegion);
00044       void addGeometry (const GLTexture::MatrixList &ml,
00045                      const CompRegion            &r,
00046                      int                         min,
00047                      int                         max);
00048 
00049     private:
00050 
00051       MatrixListVector collectedMatrixLists;
00052       CompRegionVector collectedRegions;
00053       IntVector        collectedMinVertices;
00054       IntVector        collectedMaxVertices;
00055   };
00056 
00057   class TexGeometryCollection
00058   {
00059     public:
00060       TexGeometryCollection ();
00061       void addGeometry (const GLTexture::MatrixList &ml,
00062                      const CompRegion            &r,
00063                      int                         min,
00064                      int                         max);
00065       void setTexture (GLTexture *);
00066 
00067 #ifdef USE_MODERN_COMPIZ_GL
00068       void addGeometriesAndDrawTextureForWindow (CompWindow     *w,
00069                                            const GLMatrix &transform,
00070                                                  unsigned int    mask);
00071 #else
00072       void addGeometriesAndDrawTextureForWindow (CompWindow *, unsigned int pm);
00073 #endif
00074 
00075     private:
00076       GLTexture*         mTexture;
00077       GeometryCollection mGeometries;
00078   };
00079 
00080   class PaintInfoCollector
00081   {
00082     public:
00083 
00084       PaintInfoCollector (CompWindow *w);
00085 
00086       void collect ();
00087 #ifdef USE_MODERN_COMPIZ_GL
00088       void drawGeometriesForWindow (CompWindow     *w,
00089                                 const GLMatrix &transform,
00090                                 unsigned int    pm);
00091 #else
00092       void drawGeometriesForWindow (CompWindow *w, unsigned int pm);
00093 #endif
00094 
00095       void processGeometry (const GLTexture::MatrixList &ml,
00096                          const CompRegion            &r,
00097                          int                         min,
00098                          int                         max);
00099 
00100       void processTexture (GLTexture *tex);
00101 
00102       static PaintInfoCollector * Active ();
00103 
00104       static PaintInfoCollector *active_collector;
00105 
00106     private:
00107 
00108       /* Collected regions, textures */
00109       std::vector <TexGeometryCollection> mCollection;
00110       CompWindow                          *mWindow;
00111   };
00112 }
00113 
00114 class UnityDialogShadeTexture
00115 {
00116 public:
00117 
00118   static UnityDialogShadeTexture*
00119   create();
00120 
00121   static void
00122   onThemeChanged(GObject*   obj,
00123                  GParamSpec*  pspec,
00124                  gpointer  data);
00125 
00126   void
00127   render(float alpha);
00128 
00129   void
00130   render();
00131 
00132   const GLTexture::List&
00133   texture();
00134 
00135   UnityDialogShadeTexture();
00136   ~UnityDialogShadeTexture();
00137 
00138 private:
00139 
00140   Pixmap    mPixmap;
00141   GLTexture::List mTexture;
00142   cairo_surface_t* mSurface;
00143   cairo_t*   mCairo;
00144   Damage    mDamage;
00145 
00146   GtkWidget* mOffscreenContainer;
00147   char*    mThemeName;
00148   GtkStyle*  mStyle;
00149 
00150   float   mAlpha;
00151 
00152   void
00153   clear();
00154 
00155   void
00156   destroy();
00157 
00158   void
00159   context();
00160 };
00161 
00162 class UnityDialogWindow;
00163 
00164 class UnityDialogScreen :
00165   public PluginClassHandler <UnityDialogScreen, CompScreen>,
00166   public ScreenInterface,
00167   public GLScreenInterface,
00168   public CompositeScreenInterface,
00169   public UnitydialogOptions
00170 {
00171 public:
00172 
00173   UnityDialogScreen(CompScreen*);
00174   ~UnityDialogScreen();
00175 
00176   void
00177   handleEvent(XEvent*);
00178 
00179   void
00180   handleCompizEvent(const char*, const char*, CompOption::Vector&);
00181 
00182   void
00183   matchExpHandlerChanged();
00184 
00185   CompMatch::Expression*
00186   matchInitExp(const CompString& value);
00187 
00188   void
00189   preparePaint(int);
00190 
00191   bool
00192   glPaintOutput(const GLScreenPaintAttrib& attrib,
00193                 const GLMatrix&    transform,
00194                 const CompRegion&    region,
00195                 CompOutput*    output,
00196                 unsigned int    mask);
00197 
00198   void
00199   donePaint();
00200 
00201   void
00202   optionChanged(CompOption*, Options num);
00203 
00204   void
00205   trackParent(CompWindow* w);
00206 
00207   void
00208   untrackParent(CompWindow* w);
00209 
00210 public:
00211 
00212   CompositeScreen* cScreen;
00213   GLScreen*  gScreen;
00214 
00215   bool              switchingVp()
00216   {
00217     return mSwitchingVp;
00218   }
00219   const GLTexture::List& tex()
00220   {
00221     return mTex->texture();
00222   }
00223 
00224 private:
00225 
00226   bool    mSwitchingVp;
00227   UnityDialogShadeTexture* mTex;
00228 
00229   Atom    mCompizResizeAtom;
00230   Atom    mUnityIsParentAtom;
00231 
00232   CompWindowList  mParentWindows;
00233 };
00234 
00235 #define UNITY_DIALOG_SCREEN(s)                   \
00236     UnityDialogScreen *uds = UnityDialogScreen::get (s);
00237 
00238 class UnityDialogWindow :
00239   public PluginClassHandler <UnityDialogWindow, CompWindow>,
00240   public WindowInterface,
00241   public GLWindowInterface
00242 {
00243 public:
00244 
00245   UnityDialogWindow(CompWindow* w);
00246   ~UnityDialogWindow();
00247 
00248 public:
00249 
00250   CompWindow* window;
00251   CompositeWindow* cWindow;
00252   GLWindow*   gWindow;
00253 
00254 public:
00255 
00256   bool
00257   glDraw(const GLMatrix&,
00258 #ifdef USE_MODERN_COMPIZ_GL
00259          const GLWindowPaintAttrib&,
00260 #else
00261          GLFragment::Attrib&,
00262 #endif
00263          const CompRegion&, unsigned int);
00264 
00265   bool
00266   glPaint(const GLWindowPaintAttrib&, const GLMatrix&,
00267           const CompRegion&, unsigned int);
00268 
00269   void
00270   glAddGeometry(const GLTexture::MatrixList& matrices,
00271                 const CompRegion& region,
00272                 const CompRegion& clipRegion,
00273                 unsigned int min,
00274                 unsigned int max);
00275 
00276   void
00277   glDrawTexture(GLTexture* texture,
00278 #ifdef USE_MODERN_COMPIZ_GL
00279                 const GLMatrix& transform,
00280                 const GLWindowPaintAttrib& attrib,
00281 #else
00282                 GLFragment::Attrib& attrib,
00283 #endif
00284                 unsigned int mask);
00285 
00286 
00287   void windowNotify(CompWindowNotify n);
00288   void grabNotify(int x, int y,
00289                   unsigned int state,
00290                   unsigned int mask);
00291   void ungrabNotify();
00292   void moveNotify(int x, int y, bool immediate);
00293   void resizeNotify(int, int, int, int);
00294 
00295   bool place(CompPoint&);
00296 
00297   void getAllowedActions(unsigned int& setActions, unsigned int& clearActions);
00298 
00299   /* True if on adding or removing transient, window becomes
00300    * or ceases to become a parent window */
00301   bool addTransient(CompWindow* transient);
00302   bool removeTransient(CompWindow* transient);
00303 
00304   bool hasParent()
00305   {
00306     return mParent != NULL;
00307   }
00308   bool hasTransients()
00309   {
00310     return !mTransients.empty();
00311   }
00312   bool hasTransient(CompWindow* w)
00313   {
00314     return std::find(mTransients.begin(),
00315                      mTransients.end(),
00316                      w) == mTransients.end();
00317   }
00318 
00319   CompWindow*
00320   findTopParentWindow();
00321 
00322   CompPoint getChildCenteredPositionForRect(CompRect rect);
00323   CompPoint getParentCenteredPositionForRect(CompRect rect);
00324 
00325   void    moveTransientsToRect(CompWindow* skip, CompRect rect, bool);
00326   void    moveParentToRect(CompWindow* requestor, CompRect rect, bool);
00327 
00328   void      moveToRect(CompRect currentRect, bool sync);
00329 
00330   void    grabTransients(CompWindow* skip, int x, int y,
00331                          unsigned int state, unsigned int mask, bool);
00332   void    grabParent(CompWindow* requestor, int x, int y,
00333                      unsigned int state, unsigned int mask, bool);
00334 
00335   void      animateTransients(CompWindow* skip, CompPoint& orig, CompPoint& dest, bool cont);
00336   void    animateParent(CompWindow* requestor, CompPoint& orig, CompPoint& dest);
00337 
00338   void      setMaxConstrainingAreas();
00339 
00340   CompWindow* transientParent();
00341 
00342   void adjustIPW();
00343 
00344   bool animate(int ms, float fadeTime);
00345   CompRegion getDamageRegion();
00346 
00347   void setIsAnimated(bool animated)
00348   {
00349     mIsAnimated = animated;
00350   }
00351   bool isAnimated()
00352   {
00353     return mIsAnimated;
00354   }
00355 
00356 private:
00357 
00358   bool         mSkipNotify;
00359   CompWindowList mTransients;
00360   CompWindow*     mParent;
00361   CompSize       mOldHintsSize;
00362   int        mGrabMask;
00363   int        mShadeProgress;
00364   CompPoint      mTargetPos;
00365   CompPoint      mCurrentPos;
00366   CompPoint      mOffset;
00367   XWindowChanges mDiffXWC;
00368   Window         mIpw;
00369   bool           mIsAnimated;
00370 
00371   void collectDrawInfo();
00372 };
00373 
00374 #define VIG_WINDOW(w)                  \
00375     UnityDialogWindow *vw = UnityDialogWindow::get (w);
00376 
00377 class UnityDialogPluginVTable :
00378   public CompPlugin::VTableForScreenAndWindow <UnityDialogScreen, UnityDialogWindow>
00379 {
00380 public:
00381 
00382   bool init();
00383 };