Back to index

unity  6.0.0
Launcher.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  * Authored by: Jay Taoko <jay.taoko@canonical.com>
00019  */
00020 
00021 #ifndef LAUNCHER_H
00022 #define LAUNCHER_H
00023 
00024 #include <Nux/View.h>
00025 #include <Nux/BaseWindow.h>
00026 #include <Nux/TimerProc.h>
00027 #include <NuxGraphics/IOpenGLAsmShader.h>
00028 
00029 #include "PointerBarrier.h"
00030 #include "unity-shared/AbstractIconRenderer.h"
00031 #include "unity-shared/BackgroundEffectHelper.h"
00032 #include "DNDCollectionWindow.h"
00033 #include "DndData.h"
00034 #include "EdgeBarrierController.h"
00035 #include "GeisAdapter.h"
00036 #include "unity-shared/Introspectable.h"
00037 #include "LauncherModel.h"
00038 #include "LauncherOptions.h"
00039 #include "LauncherDragWindow.h"
00040 #include "LauncherHideMachine.h"
00041 #include "LauncherHoverMachine.h"
00042 #include "unity-shared/UBusWrapper.h"
00043 #include "SoftwareCenterLauncherIcon.h"
00044 
00045 
00046 namespace unity
00047 {
00048 namespace launcher
00049 {
00050 extern const char window_title[];
00051 
00052 class AbstractLauncherIcon;
00053 
00054 class Launcher : public unity::debug::Introspectable, public nux::View, public ui::EdgeBarrierSubscriber
00055 {
00056   NUX_DECLARE_OBJECT_TYPE(Launcher, nux::View);
00057 public:
00058 
00059   Launcher(nux::BaseWindow* parent, NUX_FILE_LINE_PROTO);
00060 
00061   nux::Property<Display*> display;
00062   nux::Property<int> monitor;
00063   nux::Property<Options::Ptr> options;
00064 
00065   virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
00066   virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
00067   virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
00068 
00069   AbstractLauncherIcon::Ptr GetSelectedMenuIcon() const;
00070 
00071   void SetIconSize(int tile_size, int icon_size);
00072   int GetIconSize() const;
00073 
00074   bool Hidden() const
00075   {
00076     return _hidden;
00077   }
00078 
00079   void ForceReveal(bool force);
00080   void ShowShortcuts(bool show);
00081 
00082   void SetModel(LauncherModel::Ptr model);
00083   LauncherModel::Ptr GetModel() const;
00084 
00085   void StartKeyShowLauncher();
00086   void EndKeyShowLauncher();
00087 
00088   void EnsureIconOnScreen(AbstractLauncherIcon::Ptr icon);
00089 
00090   void SetBacklightMode(BacklightMode mode);
00091   BacklightMode GetBacklightMode() const;
00092   bool IsBackLightModeToggles() const;
00093 
00094   nux::BaseWindow* GetParent() const
00095   {
00096     return _parent;
00097   };
00098 
00099   nux::ObjectPtr<nux::View> GetActiveTooltip() const;  // nullptr = no tooltip
00100 
00101   virtual void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
00102   virtual void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
00103   virtual void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00104   virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
00105   virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
00106   virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00107   virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);
00108 
00109   virtual void RecvQuicklistOpened(QuicklistView* quicklist);
00110   virtual void RecvQuicklistClosed(QuicklistView* quicklist);
00111 
00112   int GetMouseX() const;
00113   int GetMouseY() const;
00114 
00115   void Resize();
00116 
00117   sigc::signal<void, char*, AbstractLauncherIcon::Ptr> launcher_addrequest;
00118   sigc::signal<void, AbstractLauncherIcon::Ptr> launcher_removerequest;
00119   sigc::signal<void, AbstractLauncherIcon::Ptr> icon_animation_complete;
00120   sigc::signal<void> selection_change;
00121   sigc::signal<void> hidden_changed;
00122   sigc::signal<void> sc_launcher_icon_animation;
00123   sigc::connection sc_launcher_icon_animation_connection;
00124 
00125   virtual bool InspectKeyEvent(unsigned int eventType,
00126                                unsigned int keysym,
00127                                const char* character);
00128 
00129   void EnterKeyNavMode();
00130   void ExitKeyNavMode();
00131   bool IsInKeyNavMode() const;
00132 
00133   bool IsOverlayOpen() const;
00134 
00135   static const int ANIM_DURATION_SHORT;
00136 
00137   void RenderIconToTexture(nux::GraphicsEngine& GfxContext, AbstractLauncherIcon::Ptr icon, nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
00138 
00139 protected:
00140   // Introspectable methods
00141   std::string GetName() const;
00142   void AddProperties(GVariantBuilder* builder);
00143 
00144   void ProcessDndEnter();
00145   void ProcessDndLeave();
00146   void ProcessDndMove(int x, int y, std::list<char*> mimes);
00147   void ProcessDndDrop(int x, int y);
00148 private:
00149   typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
00150 
00151   LauncherHideMode GetHideMode() const;
00152   void SetHideMode(LauncherHideMode hidemode);
00153 
00154   typedef enum
00155   {
00156     ACTION_NONE,
00157     ACTION_DRAG_LAUNCHER,
00158     ACTION_DRAG_ICON,
00159     ACTION_DRAG_EXTERNAL,
00160   } LauncherActionState;
00161 
00162   typedef enum
00163   {
00164     TIME_ENTER,
00165     TIME_LEAVE,
00166     TIME_DRAG_END,
00167     TIME_DRAG_THRESHOLD,
00168     TIME_AUTOHIDE,
00169     TIME_DRAG_EDGE_TOUCH,
00170     TIME_DRAG_OUT,
00171     TIME_TAP_SUPER,
00172     TIME_SUPER_PRESSED,
00173 
00174     TIME_LAST
00175   } LauncherActionTimes;
00176 
00177   void ConfigureBarrier();
00178 
00179   void OnOptionsChanged(Options::Ptr options);
00180   void OnOptionChanged();
00181   void UpdateOptions(Options::Ptr options);
00182 
00183   void OnWindowMapped(guint32 xid);
00184   void OnWindowUnmapped(guint32 xid);
00185 
00186   void OnDragStart(GeisAdapter::GeisDragData* data);
00187   void OnDragUpdate(GeisAdapter::GeisDragData* data);
00188   void OnDragFinish(GeisAdapter::GeisDragData* data);
00189 
00190   bool HandleBarrierEvent(ui::PointerBarrierWrapper* owner, ui::BarrierEvent::Ptr event);
00191 
00192   void OnPluginStateChanged();
00193 
00194   void OnSelectionChanged(AbstractLauncherIcon::Ptr selection);
00195 
00196   bool StrutHack();
00197   bool StartIconDragTimeout();
00198   bool OnScrollTimeout();
00199   bool OnUpdateDragManagerTimeout();
00200 
00201   void SetMousePosition(int x, int y);
00202 
00203   void SetStateMouseOverLauncher(bool over_launcher);
00204 
00205   bool MouseBeyondDragThreshold() const;
00206 
00207   void OnDragWindowAnimCompleted();
00208 
00209   bool IconNeedsAnimation(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00210   bool IconDrawEdgeOnly(AbstractLauncherIcon::Ptr icon) const;
00211   bool AnimationInProgress() const;
00212 
00213   void SetActionState(LauncherActionState actionstate);
00214   LauncherActionState GetActionState() const;
00215 
00216   void EnsureAnimation();
00217   void EnsureScrollTimer();
00218 
00219   bool MouseOverTopScrollArea();
00220   bool MouseOverTopScrollExtrema();
00221 
00222   bool MouseOverBottomScrollArea();
00223   bool MouseOverBottomScrollExtrema();
00224 
00225   float DnDStartProgress(struct timespec const& current) const;
00226   float DnDExitProgress(struct timespec const& current) const;
00227   float GetHoverProgress(struct timespec const& current) const;
00228   float AutohideProgress(struct timespec const& current) const;
00229   float DragThresholdProgress(struct timespec const& current) const;
00230   float DragHideProgress(struct timespec const& current) const;
00231   float DragOutProgress(struct timespec const& current) const;
00232   float IconDesatValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00233   float IconPresentProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00234   float IconUrgentProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00235   float IconShimmerProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00236   float IconUrgentPulseValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00237   float IconPulseOnceValue(AbstractLauncherIcon::Ptr icon, struct timespec const &current) const;
00238   float IconUrgentWiggleValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00239   float IconStartingBlinkValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00240   float IconStartingPulseValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00241   float IconBackgroundIntensity(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00242   float IconProgressBias(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00243   float IconDropDimValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00244   float IconCenterTransitionProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00245   float IconVisibleProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const;
00246 
00247   void SetHover(bool hovered);
00248   void SetHidden(bool hidden);
00249 
00250   void  SetDndDelta(float x, float y, nux::Geometry const& geo, timespec const& current);
00251   float DragLimiter(float x);
00252 
00253   void SetupRenderArg(AbstractLauncherIcon::Ptr icon, struct timespec const& current, ui::RenderArg& arg);
00254   void FillRenderArg(AbstractLauncherIcon::Ptr icon,
00255                      ui::RenderArg& arg,
00256                      nux::Point3& center,
00257                      nux::Geometry const& parent_abs_geo,
00258                      float folding_threshold,
00259                      float folded_size,
00260                      float folded_spacing,
00261                      float autohide_offset,
00262                      float folded_z_distance,
00263                      float animation_neg_rads,
00264                      struct timespec const& current);
00265 
00266   void RenderArgs(std::list<ui::RenderArg> &launcher_args,
00267                   nux::Geometry& box_geo, float* launcher_alpha, nux::Geometry const& parent_abs_geo);
00268 
00269   void OnIconAdded(AbstractLauncherIcon::Ptr icon);
00270   void OnIconRemoved(AbstractLauncherIcon::Ptr icon);
00271   void OnOrderChanged();
00272 
00273   void OnIconNeedsRedraw(AbstractLauncherIcon::Ptr icon);
00274   void OnTooltipVisible(nux::ObjectPtr<nux::View> view);
00275 
00276   void OnOverlayHidden(GVariant* data);
00277   void OnOverlayShown(GVariant* data);
00278 
00279   void DesaturateIcons();
00280   void SaturateIcons();
00281 
00282   void OnBGColorChanged(GVariant *data);
00283 
00284   void OnLockHideChanged(GVariant *data);
00285 
00286   void OnActionDone(GVariant* data);
00287 
00288   AbstractLauncherIcon::Ptr MouseIconIntersection(int x, int y);
00289   void EventLogic();
00290   void MouseDownLogic(int x, int y, unsigned long button_flags, unsigned long key_flags);
00291   void MouseUpLogic(int x, int y, unsigned long button_flags, unsigned long key_flags);
00292 
00293   void StartIconDragRequest(int x, int y);
00294   void StartIconDrag(AbstractLauncherIcon::Ptr icon);
00295   void EndIconDrag();
00296   void UpdateDragWindowPosition(int x, int y);
00297 
00298   void ResetMouseDragState();
00299 
00300   float GetAutohidePositionMin() const;
00301   float GetAutohidePositionMax() const;
00302 
00303   virtual long PostLayoutManagement(long LayoutResult);
00304 
00305   void SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
00306   void RestoreSystemRenderTarget();
00307 
00308   void OnDisplayChanged(Display* display);
00309   void OnDNDDataCollected(const std::list<char*>& mimes);
00310 
00311   void DndReset();
00312   void DndHoveredIconReset();
00313   void DndTimeoutSetup();
00314 
00315   LauncherModel::Ptr _model;
00316   nux::BaseWindow* _parent;
00317   nux::ObjectPtr<nux::View> _active_tooltip;
00318   QuicklistView* _active_quicklist;
00319 
00320   nux::HLayout* m_Layout;
00321 
00322   // used by keyboard/a11y-navigation
00323   AbstractLauncherIcon::Ptr _icon_under_mouse;
00324   AbstractLauncherIcon::Ptr _icon_mouse_down;
00325   AbstractLauncherIcon::Ptr _drag_icon;
00326   AbstractLauncherIcon::Ptr _dnd_hovered_icon;
00327 
00328   bool _hovered;
00329   bool _hidden;
00330   bool _scroll_limit_reached;
00331   bool _render_drag_window;
00332   bool _shortcuts_shown;
00333   bool _data_checked;
00334   bool _steal_drag;
00335   bool _drag_edge_touching;
00336   bool _initial_drag_animation;
00337   bool _dash_is_open;
00338   bool _hud_is_open;
00339 
00340   BacklightMode _backlight_mode;
00341 
00342   float _folded_angle;
00343   float _neg_folded_angle;
00344   float _folded_z_distance;
00345   float _last_delta_y;
00346   float _edge_overcome_pressure;
00347 
00348   LauncherActionState _launcher_action_state;
00349   LaunchAnimation _launch_animation;
00350   UrgentAnimation _urgent_animation;
00351 
00352   int _space_between_icons;
00353   int _icon_image_size;
00354   int _icon_image_size_delta;
00355   int _icon_glow_size;
00356   int _icon_size;
00357   int _dnd_delta_y;
00358   int _dnd_delta_x;
00359   int _postreveal_mousemove_delta_x;
00360   int _postreveal_mousemove_delta_y;
00361   int _launcher_drag_delta;
00362   int _enter_y;
00363   int _last_button_press;
00364   int _drag_out_id;
00365   float _drag_out_delta_x;
00366   float _last_reveal_progress;
00367 
00368   nux::Point2 _mouse_position;
00369   nux::ObjectPtr<nux::IOpenGLBaseTexture> _offscreen_drag_texture;
00370   nux::ObjectPtr<LauncherDragWindow> _drag_window;
00371   nux::ObjectPtr<unity::DNDCollectionWindow> _collection_window;
00372   LauncherHideMachine _hide_machine;
00373   LauncherHoverMachine _hover_machine;
00374 
00375   unity::DndData _dnd_data;
00376   nux::DndAction _drag_action;
00377   Atom _selection_atom;
00378 
00379   struct timespec  _times[TIME_LAST];
00380 
00381   nux::Color _background_color;
00382   BaseTexturePtr launcher_sheen_;
00383   BaseTexturePtr launcher_pressure_effect_;
00384 
00385   ui::AbstractIconRenderer::Ptr icon_renderer;
00386   BackgroundEffectHelper bg_effect_helper_;
00387 
00388   UBusManager ubus_;
00389   glib::SourceManager sources_;
00390 };
00391 
00392 }
00393 }
00394 
00395 #endif // LAUNCHER_H