Back to index

unity  6.0.0
unityshell.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /* Compiz unity plugin
00003  * unity.h
00004  *
00005  * Copyright (c) 2010-11 Canonical Ltd.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 3
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * Your own copyright notice would go above. You are free to choose whatever
00018  * licence you want, just take note that some compiz code is GPL and you will
00019  * not be able to re-use it if you want to use a different licence.
00020  */
00021 
00022 #ifndef UNITYSHELL_H
00023 #define UNITYSHELL_H
00024 
00025 #include <Nux/WindowThread.h>
00026 #include <NuxCore/Property.h>
00027 #include <sigc++/sigc++.h>
00028 #include <boost/shared_ptr.hpp>
00029 
00030 #include <core/core.h>
00031 #include <core/pluginclasshandler.h>
00032 #include <composite/composite.h>
00033 #include <opengl/opengl.h>
00034 
00035 #include "unityshell_options.h"
00036 
00037 #include "Introspectable.h"
00038 #include "DashController.h"
00039 #include "UnitySettings.h"
00040 #include "DashStyle.h"
00041 #include "FavoriteStoreGSettings.h"
00042 #include "FontSettings.h"
00043 #include "ShortcutController.h"
00044 #include "ShortcutHint.h"
00045 #include "LauncherController.h"
00046 #include "PanelController.h"
00047 #include "PanelStyle.h"
00048 #include "UScreen.h"
00049 #include "GestureEngine.h"
00050 #include "DebugDBusInterface.h"
00051 #include "SwitcherController.h"
00052 #include "UBusWrapper.h"
00053 #include "UnityshellPrivate.h"
00054 #include "UnityShowdesktopHandler.h"
00055 #ifndef USE_MODERN_COMPIZ_GL
00056 #include "ScreenEffectFramebufferObject.h"
00057 #endif
00058 
00059 #include "compizminimizedwindowhandler.h"
00060 #include "BGHash.h"
00061 #include <compiztoolbox/compiztoolbox.h>
00062 #include <dlfcn.h>
00063 
00064 #include "HudController.h"
00065 
00066 namespace unity
00067 {
00068 
00069 /* base screen class */
00070 class UnityScreen :
00071   public unity::debug::Introspectable,
00072   public sigc::trackable,
00073   public ScreenInterface,
00074   public CompositeScreenInterface,
00075   public GLScreenInterface,
00076   public BaseSwitchScreen,
00077   public PluginClassHandler <UnityScreen, CompScreen>,
00078   public UnityshellOptions
00079 {
00080 public:
00081   UnityScreen(CompScreen* s);
00082   ~UnityScreen();
00083 
00084   /* We store these  to avoid unecessary calls to ::get */
00085   CompScreen* screen;
00086   CompositeScreen* cScreen;
00087   GLScreen* gScreen;
00088 
00089   /* prepares nux for drawing */
00090   void nuxPrologue();
00091   /* pops nux draw stack */
00092   void nuxEpilogue();
00093 
00094   /* nux draw wrapper */
00095 #ifdef USE_MODERN_COMPIZ_GL
00096   void paintDisplay();
00097 #else
00098   void paintDisplay(const CompRegion& region, const GLMatrix& transform, unsigned int mask);
00099 #endif
00100   void paintPanelShadow(const GLMatrix& matrix);
00101   void setPanelShadowMatrix(const GLMatrix& matrix);
00102 
00103   void preparePaint (int ms);
00104   void paintFboForOutput (CompOutput *output);
00105   void donePaint ();
00106 
00107   void RaiseInputWindows();
00108 
00109   void
00110   handleCompizEvent (const char         *pluginName,
00111                      const char         *eventName,
00112                      CompOption::Vector &o);
00113 
00114   void damageRegion(const CompRegion &region);
00115 
00116   /* paint on top of all windows if we could not find a window
00117    * to paint underneath */
00118   bool glPaintOutput(const GLScreenPaintAttrib&,
00119                      const GLMatrix&,
00120                      const CompRegion&,
00121                      CompOutput*,
00122                      unsigned int);
00123 #ifdef USE_MODERN_COMPIZ_GL
00124   void glPaintCompositedOutput (const CompRegion    &region,
00125                                 ::GLFramebufferObject *fbo,
00126                                 unsigned int         mask);
00127 #endif
00128 
00129   /* paint in the special case that the output is transformed */
00130   void glPaintTransformedOutput(const GLScreenPaintAttrib&,
00131                                 const GLMatrix&,
00132                                 const CompRegion&,
00133                                 CompOutput*,
00134                                 unsigned int);
00135 
00136   /* handle X11 events */
00137   void handleEvent(XEvent*);
00138 
00139   /* handle showdesktop */
00140   void enterShowDesktopMode ();
00141   void leaveShowDesktopMode (CompWindow *w);
00142 
00143   bool showLauncherKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00144   bool showLauncherKeyTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00145   bool showPanelFirstMenuKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00146   bool showPanelFirstMenuKeyTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00147 
00148   bool executeCommand(CompAction* action, CompAction::State state, CompOption::Vector& options);
00149   bool setKeyboardFocusKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00150 
00151   bool altTabInitiateCommon(CompAction* action, switcher::ShowMode mode);
00152   bool altTabTerminateCommon(CompAction* action,
00153                              CompAction::State state,
00154                              CompOption::Vector& options);
00155 
00156   bool altTabForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00157   bool altTabPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00158   bool altTabForwardAllInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00159   bool altTabPrevAllInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00160   bool altTabDetailStartInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00161   bool altTabDetailStopInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00162   bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00163   bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00164 
00165   bool ShowHud();
00166   /* handle hud key activations */
00167   bool ShowHudInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00168   bool ShowHudTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00169   bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00170   bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00171   bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
00172 
00173   /* handle option changes and change settings inside of the
00174    * panel and dock views */
00175   void optionChanged(CompOption*, Options num);
00176 
00177   /* Handle changes in the number of workspaces by showing the switcher
00178    * or not showing the switcher */
00179   bool setOptionForPlugin(const char* plugin, const char* name,
00180                           CompOption::Value& v);
00181 
00182   /* init plugin actions for screen */
00183   bool initPluginForScreen(CompPlugin* p);
00184 
00185   void outputChangeNotify();
00186   void NeedsRelayout();
00187   void ScheduleRelayout(guint timeout);
00188 
00189   bool forcePaintOnTop ();
00190 
00191 protected:
00192   std::string GetName() const;
00193   void AddProperties(GVariantBuilder* builder);
00194 
00195 private:
00196   enum CancelActionTarget
00197   {
00198     LAUNCHER_SWITCHER,
00199     SHORTCUT_HINT
00200   };
00201 
00202   void initAltTabNextWindow ();
00203 
00204   void SendExecuteCommand();
00205 
00206   void EnsureSuperKeybindings();
00207   void CreateSuperNewAction(char shortcut, impl::ActionModifiers flag);
00208   void EnableCancelAction(CancelActionTarget target, bool enabled, int modifiers = 0);
00209 
00210   bool initPluginActions();
00211   void initLauncher();
00212 
00213   void compizDamageNux(CompRegion const& region);
00214   void nuxDamageCompiz();
00215 
00216   void onRedrawRequested();
00217   void Relayout();
00218 
00219   static void initUnity(nux::NThread* thread, void* InitData);
00220   static void OnStartKeyNav(GVariant* data, void* value);
00221   static void OnExitKeyNav(GVariant* data, void* value);
00222 
00223   void restartLauncherKeyNav();
00224 
00225   void OnDashRealized ();
00226 
00227   void OnLauncherStartKeyNav(GVariant* data);
00228   void OnLauncherEndKeyNav(GVariant* data);
00229 
00230   void OnSwitcherStart(GVariant* data);
00231   void OnSwitcherEnd(GVariant* data);
00232 
00233   void RestoreWindow(GVariant* data);
00234   bool SaveInputThenFocus(const guint xid);
00235 
00236   void InitHints();
00237 
00238   void OnPanelStyleChanged();
00239 
00240   Settings dash_settings_;
00241   dash::Style    dash_style_;
00242   panel::Style   panel_style_;
00243   FontSettings   font_settings_;
00244   GeisAdapter    geis_adapter_;
00245   internal::FavoriteStoreGSettings favorite_store_;
00246 
00247   /* The window thread should be the last thing removed, as c++ does it in reverse order */
00248   std::unique_ptr<nux::WindowThread> wt;
00249 
00250   /* These must stay below the window thread, please keep the order */
00251   launcher::Controller::Ptr launcher_controller_;
00252   dash::Controller::Ptr     dash_controller_;
00253   panel::Controller::Ptr    panel_controller_;
00254   switcher::Controller::Ptr switcher_controller_;
00255   hud::Controller::Ptr      hud_controller_;
00256   shortcut::Controller::Ptr shortcut_controller_;
00257   debug::DebugDBusInterface debugger_;
00258 
00259   std::list<shortcut::AbstractHint::Ptr> hints_;
00260   bool enable_shortcut_overlay_;
00261 
00262   GestureEngine                         gesture_engine_;
00263   bool                                  needsRelayout;
00264   bool                                  _in_paint;
00265   bool                                  super_keypressed_;
00266   typedef std::shared_ptr<CompAction> CompActionPtr;
00267   typedef std::vector<CompActionPtr> ShortcutActions;
00268   ShortcutActions _shortcut_actions;
00269   std::map<CancelActionTarget, CompActionPtr> _escape_actions;
00270 
00271   /* keyboard-nav mode */
00272   CompWindow* newFocusedWindow;
00273   CompWindow* lastFocusedWindow;
00274 
00275   GLTexture::List _shadow_texture;
00276 
00277   /* handle paint order */
00278   bool    doShellRepaint;
00279   bool    didShellRepaint;
00280   bool    allowWindowPaint;
00281   bool    _key_nav_mode_requested;
00282   CompOutput* _last_output;
00283 
00284   CompRegion nuxRegion;
00285   CompRegion fullscreenRegion;
00286   CompWindow* firstWindowAboveShell;
00287 
00288   nux::Property<nux::Geometry> primary_monitor_;
00289 
00290   BGHash _bghash;
00291 
00292 #ifdef USE_MODERN_COMPIZ_GL
00293   ::GLFramebufferObject *oldFbo;
00294 #else
00295   ScreenEffectFramebufferObject::Ptr _fbo;
00296   GLuint                             _active_fbo;
00297 #endif
00298 
00299   bool   queryForShader ();
00300 
00301   int dash_monitor_;
00302   CompScreen::GrabHandle grab_index_;
00303   CompWindowList         fullscreen_windows_;
00304   bool                   painting_tray_;
00305   unsigned int           tray_paint_mask_;
00306   unsigned int           last_scroll_event_;
00307   int                    hud_keypress_time_;
00308   int                    first_menu_keypress_time_;
00309 
00310   GLMatrix panel_shadow_matrix_;
00311 
00312   bool panel_texture_has_changed_;
00313   bool paint_panel_;
00314   nux::ObjectPtr<nux::IOpenGLBaseTexture> panel_texture_;
00315 
00316   bool scale_just_activated_;
00317 
00318 #ifndef USE_MODERN_COMPIZ_GL
00319   ScreenEffectFramebufferObject::GLXGetProcAddressProc glXGetProcAddressP;
00320 #endif
00321 
00322   UBusManager ubus_manager_;
00323   glib::SourceManager sources_;
00324 
00325   friend class UnityWindow;
00326 };
00327 
00328 class UnityWindow :
00329   public WindowInterface,
00330   public GLWindowInterface,
00331   public ShowdesktopHandlerWindowInterface,
00332   public compiz::WindowInputRemoverLockAcquireInterface,
00333   public BaseSwitchWindow,
00334   public PluginClassHandler <UnityWindow, CompWindow>
00335 {
00336 public:
00337   UnityWindow(CompWindow*);
00338   ~UnityWindow();
00339 
00340   CompWindow* window;
00341   GLWindow* gWindow;
00342 
00343   nux::Geometry last_bound;
00344 
00345   void minimize ();
00346   void unminimize ();
00347   bool minimized ();
00348   bool focus ();
00349   void activate ();
00350 
00351   void updateFrameRegion (CompRegion &region);
00352 
00353   /* occlusion detection
00354    * and window hiding */
00355   bool glPaint(const GLWindowPaintAttrib& attrib,
00356                const GLMatrix&            matrix,
00357                const CompRegion&          region,
00358                unsigned int              mask);
00359 
00360   /* basic window draw function */
00361   bool glDraw(const GLMatrix& matrix,
00362 #ifndef USE_MODERN_COMPIZ_GL
00363               GLFragment::Attrib& attrib,
00364 #else
00365               const GLWindowPaintAttrib& attrib,
00366 #endif
00367               const CompRegion& region,
00368               unsigned intmask);
00369 
00370   void updateIconPos (int   &wx,
00371                       int   &wy,
00372                       int   x,
00373                       int   y,
00374                       float width,
00375                       float height);
00376 
00377   void windowNotify(CompWindowNotify n);
00378   void moveNotify(int x, int y, bool immediate);
00379   void resizeNotify(int x, int y, int w, int h);
00380   void stateChangeNotify(unsigned int lastState);
00381 
00382   bool place(CompPoint& pos);
00383   CompPoint tryNotIntersectUI(CompPoint& pos);
00384 
00385   void paintThumbnail (nux::Geometry const& bounding, float alpha);
00386 
00387   void enterShowDesktop ();
00388   void leaveShowDesktop ();
00389   bool HandleAnimations (unsigned int ms);
00390 
00391   void handleEvent (XEvent *event);
00392 
00393   typedef compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow>
00394           UnityMinimizedHandler;
00395   std::unique_ptr <UnityMinimizedHandler> mMinimizeHandler;
00396 
00397   ShowdesktopHandler             *mShowdesktopHandler;
00398 
00399 private:
00400   void DoEnableFocus ();
00401   void DoDisableFocus ();
00402 
00403   bool IsOverrideRedirect ();
00404   bool IsManaged ();
00405   bool IsGrabbed ();
00406   bool IsDesktopOrDock ();
00407   bool IsSkipTaskbarOrPager ();
00408   bool IsHidden ();
00409   bool IsInShowdesktopMode ();
00410   bool IsShaded ();
00411   bool IsMinimized ();
00412   void DoOverrideFrameRegion (CompRegion &r);
00413 
00414   void DoHide ();
00415   void DoNotifyHidden ();
00416   void DoShow ();
00417   void DoNotifyShown ();
00418 
00419   void DoAddDamage ();
00420   ShowdesktopHandlerWindowInterface::PostPaintAction DoHandleAnimations (unsigned int ms);
00421 
00422   void DoMoveFocusAway ();
00423 
00424   void DoDeleteHandler ();
00425 
00426   unsigned int GetNoCoreInstanceMask ();
00427 
00428   compiz::WindowInputRemoverLock::Ptr GetInputRemover ();
00429 
00430   compiz::WindowInputRemoverLock::Weak input_remover_;
00431   glib::Source::UniquePtr focus_desktop_timeout_;
00432 };
00433 
00434 
00438 class UnityPluginVTable :
00439   public CompPlugin::VTableForScreenAndWindow<UnityScreen, UnityWindow>
00440 {
00441 public:
00442   bool init();
00443 };
00444 
00445 } // namespace unity
00446 
00447 #endif // UNITYSHELL_H