1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2010 Canonical Ltd
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by: Jason Smith <jason.smith@canonical.com>
18
* Authored by: Jay Taoko <jay.taoko@canonical.com>
27
#include <Nux/BaseWindow.h>
28
#include <Nux/TimerProc.h>
29
#include <NuxGraphics/IOpenGLAsmShader.h>
31
#include "AbstractIconRenderer.h"
32
#include "BackgroundEffectHelper.h"
33
#include "DNDCollectionWindow.h"
35
#include "GeisAdapter.h"
36
#include "Introspectable.h"
37
#include "LauncherIcon.h"
38
#include "LauncherDragWindow.h"
39
#include "LauncherHideMachine.h"
40
#include "LauncherHoverMachine.h"
42
#define ANIM_DURATION_SHORT_SHORT 100
43
#define ANIM_DURATION_SHORT 125
44
#define ANIM_DURATION 200
45
#define ANIM_DURATION_LONG 350
47
#define SUPER_TAP_DURATION 250
48
#define SHORTCUTS_SHOWN_DELAY 750
49
#define START_DRAGICON_DURATION 250
50
#define BEFORE_HIDE_LAUNCHER_ON_SUPER_DURATION 1000
52
#define IGNORE_REPEAT_SHORTCUT_DURATION 250
54
#define MAX_SUPERKEY_LABELS 10
59
class LauncherDragWindow;
62
using namespace unity::ui;
64
class Launcher : public unity::Introspectable, public nux::View
66
NUX_DECLARE_OBJECT_TYPE(Launcher, nux::View);
71
LAUNCHER_HIDE_AUTOHIDE,
72
LAUNCHER_HIDE_DODGE_WINDOWS,
73
LAUNCHER_HIDE_DODGE_ACTIVE_WINDOW,
78
LAUNCH_ANIMATION_NONE,
79
LAUNCH_ANIMATION_PULSE,
80
LAUNCH_ANIMATION_BLINK,
85
URGENT_ANIMATION_NONE,
86
URGENT_ANIMATION_PULSE,
87
URGENT_ANIMATION_WIGGLE,
102
BACKLIGHT_ALWAYS_OFF,
103
BACKLIGHT_EDGE_TOGGLE,
104
BACKLIGHT_NORMAL_EDGE_TOGGLE
107
Launcher(nux::BaseWindow* parent, NUX_FILE_LINE_PROTO);
110
nux::Property<Display*> display;
112
virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
113
virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
114
virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
116
LauncherIcon* GetSelectedMenuIcon();
118
void SetIconSize(int tile_size, int icon_size);
119
void SetBackgroundAlpha(float background_alpha);
121
LauncherHideMachine* HideMachine() { return _hide_machine; }
129
return _hide_machine->GetShowOnEdge();
132
void SetModel(LauncherModel* model);
133
LauncherModel* GetModel();
135
void SetFloating(bool floating);
137
void SetHideMode(LauncherHideMode hidemode);
138
LauncherHideMode GetHideMode();
140
void StartKeyShowLauncher();
141
void EndKeyShowLauncher();
143
void SetBacklightMode(BacklightMode mode);
144
BacklightMode GetBacklightMode();
145
bool IsBackLightModeToggles();
147
void SetLaunchAnimation(LaunchAnimation animation);
148
LaunchAnimation GetLaunchAnimation();
150
void SetUrgentAnimation(UrgentAnimation animation);
151
UrgentAnimation GetUrgentAnimation();
153
void SetAutoHideAnimation(AutoHideAnimation animation);
154
AutoHideAnimation GetAutoHideAnimation();
156
void EdgeRevealTriggered(int x, int y);
158
gboolean CheckSuperShortcutPressed(Display *x_display, unsigned int key_sym, unsigned long key_code, unsigned long key_state, char* key_string);
159
void SetLatestShortcut(guint64 shortcut);
161
nux::BaseWindow* GetParent()
166
static void SetTimeStruct(struct timespec* timer, struct timespec* sister = 0, int sister_relation = 0);
168
virtual void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
169
virtual void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
170
virtual void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
171
virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
172
virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
173
virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
174
virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);
175
virtual void RecvMouseDownOutsideArea(int x, int y, unsigned long button_flags, unsigned long key_flags);
177
virtual void RecvKeyPressed(unsigned long eventType , /*event type*/
178
unsigned long keysym , /*event keysym*/
179
unsigned long state , /*event state*/
180
const char* character , /*character*/
181
unsigned short keyCount /*key repeat count*/);
183
virtual void RecvQuicklistOpened(QuicklistView* quicklist);
184
virtual void RecvQuicklistClosed(QuicklistView* quicklist);
186
void startKeyNavMode();
187
void leaveKeyNavMode(bool preserve_focus = true);
189
void exitKeyNavMode(); // Connected to signal OnEndFocus
194
void CheckWindowOverLauncher();
195
void EnableCheckWindowOverLauncher(gboolean enabled);
197
sigc::signal<void, char*, LauncherIcon*> launcher_addrequest;
198
sigc::signal<void, LauncherIcon*> launcher_removerequest;
199
sigc::signal<void> selection_change;
200
sigc::signal<void> hidden_changed;
204
virtual bool InspectKeyEvent(unsigned int eventType,
206
const char* character);
209
// Introspectable methods
210
const gchar* GetName();
211
void AddProperties(GVariantBuilder* builder);
213
void ProcessDndEnter();
214
void ProcessDndLeave();
215
void ProcessDndMove(int x, int y, std::list<char*> mimes);
216
void ProcessDndDrop(int x, int y);
218
typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
223
ACTION_DRAG_LAUNCHER,
225
ACTION_DRAG_EXTERNAL,
226
} LauncherActionState;
235
TIME_DRAG_EDGE_TOUCH,
241
} LauncherActionTimes;
243
void OnWindowMaybeIntellihide(guint32 xid);
244
void OnWindowMaybeIntellihideDelayed(guint32 xid);
245
static gboolean CheckWindowOverLauncherSync(Launcher* self);
246
void OnWindowMapped(guint32 xid);
247
void OnWindowUnmapped(guint32 xid);
249
void OnDragStart(GeisAdapter::GeisDragData* data);
250
void OnDragUpdate(GeisAdapter::GeisDragData* data);
251
void OnDragFinish(GeisAdapter::GeisDragData* data);
253
void OnPluginStateChanged();
255
void OnViewPortSwitchStarted();
256
void OnViewPortSwitchEnded();
258
static gboolean AnimationTimeout(gpointer data);
259
static gboolean SuperShowLauncherTimeout(gpointer data);
260
static gboolean SuperHideLauncherTimeout(gpointer data);
261
static gboolean SuperShowShortcutsTimeout(gpointer data);
262
static gboolean StrutHack(gpointer data);
263
static gboolean MoveFocusToKeyNavModeTimeout(gpointer data);
264
static gboolean StartIconDragTimeout(gpointer data);
265
static gboolean ResetRepeatShorcutTimeout(gpointer data);
267
void SetMousePosition(int x, int y);
269
void SetStateMouseOverLauncher(bool over_launcher);
270
void SetStateKeyNav(bool keynav_activated);
272
bool MouseBeyondDragThreshold();
274
void OnDragWindowAnimCompleted();
276
bool IconNeedsAnimation(LauncherIcon* icon, struct timespec const& current);
277
bool IconDrawEdgeOnly(LauncherIcon* icon);
278
bool AnimationInProgress();
280
void SetActionState(LauncherActionState actionstate);
281
LauncherActionState GetActionState();
283
void EnsureAnimation();
284
void EnsureScrollTimer();
286
bool MouseOverTopScrollArea();
287
bool MouseOverTopScrollExtrema();
289
bool MouseOverBottomScrollArea();
290
bool MouseOverBottomScrollExtrema();
292
static gboolean OnScrollTimeout(gpointer data);
293
static gboolean OnUpdateDragManagerTimeout(gpointer data);
295
float DnDStartProgress(struct timespec const& current);
296
float DnDExitProgress(struct timespec const& current);
297
float GetHoverProgress(struct timespec const& current);
298
float AutohideProgress(struct timespec const& current);
299
float DragThresholdProgress(struct timespec const& current);
300
float DragHideProgress(struct timespec const& current);
301
float DragOutProgress(struct timespec const& current);
302
float IconDesatValue(LauncherIcon* icon, struct timespec const& current);
303
float IconPresentProgress(LauncherIcon* icon, struct timespec const& current);
304
float IconUrgentProgress(LauncherIcon* icon, struct timespec const& current);
305
float IconShimmerProgress(LauncherIcon* icon, struct timespec const& current);
306
float IconUrgentPulseValue(LauncherIcon* icon, struct timespec const& current);
307
float IconPulseOnceValue(LauncherIcon *icon, struct timespec const ¤t);
308
float IconUrgentWiggleValue(LauncherIcon* icon, struct timespec const& current);
309
float IconStartingBlinkValue(LauncherIcon* icon, struct timespec const& current);
310
float IconStartingPulseValue(LauncherIcon* icon, struct timespec const& current);
311
float IconBackgroundIntensity(LauncherIcon* icon, struct timespec const& current);
312
float IconProgressBias(LauncherIcon* icon, struct timespec const& current);
313
float IconDropDimValue(LauncherIcon* icon, struct timespec const& current);
314
float IconCenterTransitionProgress(LauncherIcon* icon, struct timespec const& current);
316
void SetHover(bool hovered);
317
void SetHidden(bool hidden);
319
void SetDndDelta(float x, float y, nux::Geometry const& geo, timespec const& current);
320
float DragLimiter(float x);
322
void SetupRenderArg(LauncherIcon* icon, struct timespec const& current, RenderArg& arg);
323
void FillRenderArg(LauncherIcon* icon,
326
float folding_threshold,
328
float folded_spacing,
329
float autohide_offset,
330
float folded_z_distance,
331
float animation_neg_rads,
332
struct timespec const& current);
334
void RenderArgs(std::list<RenderArg> &launcher_args,
335
nux::Geometry& box_geo, float* launcher_alpha);
337
void OnIconAdded(LauncherIcon* icon);
338
void OnIconRemoved(LauncherIcon* icon);
339
void OnOrderChanged();
341
void OnIconNeedsRedraw(AbstractLauncherIcon* icon);
343
static void OnPlaceViewHidden(GVariant* data, void* val);
344
static void OnPlaceViewShown(GVariant* data, void* val);
346
void DesaturateIcons();
347
void SaturateIcons();
349
static void OnBGColorChanged (GVariant *data, void *val);
351
static void OnActionDone(GVariant* data, void* val);
353
void RenderIconToTexture(nux::GraphicsEngine& GfxContext, LauncherIcon* icon, nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
355
LauncherIcon* MouseIconIntersection(int x, int y);
357
void MouseDownLogic(int x, int y, unsigned long button_flags, unsigned long key_flags);
358
void MouseUpLogic(int x, int y, unsigned long button_flags, unsigned long key_flags);
360
void StartIconDragRequest(int x, int y);
361
void StartIconDrag(LauncherIcon* icon);
363
void UpdateDragWindowPosition(int x, int y);
365
float GetAutohidePositionMin();
366
float GetAutohidePositionMax();
368
virtual void PreLayoutManagement();
369
virtual long PostLayoutManagement(long LayoutResult);
370
virtual void PositionChildLayout(float offsetX, float offsetY);
372
void SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
373
void RestoreSystemRenderTarget();
375
gboolean TapOnSuper();
377
void OnDisplayChanged(Display* display);
378
void OnDNDDataCollected(const std::list<char*>& mimes);
381
void DndHoveredIconReset();
383
nux::HLayout* m_Layout;
384
int m_ContentOffsetY;
386
// used by keyboard/a11y-navigation
387
LauncherIcon* _current_icon;
388
LauncherIcon* m_ActiveTooltipIcon;
389
LauncherIcon* _icon_under_mouse;
390
LauncherIcon* _icon_mouse_down;
391
LauncherIcon* _drag_icon;
393
int _current_icon_index;
394
int _last_icon_index;
396
QuicklistView* _active_quicklist;
401
bool _render_drag_window;
402
bool _check_window_over_launcher;
404
bool _shortcuts_shown;
405
bool _keynav_activated;
406
guint64 _latest_shortcut;
408
BacklightMode _backlight_mode;
411
float _neg_folded_angle;
412
float _folded_z_distance;
413
float _launcher_top_y;
414
float _launcher_bottom_y;
416
LauncherHideMode _hidemode;
418
LauncherActionState _launcher_action_state;
419
LaunchAnimation _launch_animation;
420
UrgentAnimation _urgent_animation;
421
AutoHideAnimation _autohide_animation;
423
nux::ObjectPtr<nux::IOpenGLBaseTexture> _offscreen_drag_texture;
425
int _space_between_icons;
427
int _icon_image_size;
428
int _icon_image_size_delta;
432
int _postreveal_mousemove_delta_x;
433
int _postreveal_mousemove_delta_y;
434
int _launcher_drag_delta;
436
int _last_button_press;
438
float _drag_out_delta_x;
439
float _background_alpha;
444
guint _autoscroll_handle;
445
guint _focus_keynav_handle;
446
guint _super_show_launcher_handle;
447
guint _super_hide_launcher_handle;
448
guint _super_show_shortcuts_handle;
449
guint _start_dragicon_handle;
450
guint _dnd_check_handle;
451
guint _ignore_repeat_shortcut_handle;
453
nux::Point2 _mouse_position;
454
nux::Point2 _bfb_mouse_position;
455
nux::AbstractPaintLayer* m_BackgroundLayer;
456
nux::BaseWindow* _parent;
457
LauncherModel* _model;
458
LauncherDragWindow* _drag_window;
459
LauncherHideMachine* _hide_machine;
460
LauncherHoverMachine* _hover_machine;
462
unity::DndData _dnd_data;
463
nux::DndAction _drag_action;
466
bool _drag_edge_touching;
467
LauncherIcon* _dnd_hovered_icon;
468
unity::DNDCollectionWindow* _collection_window;
469
sigc::connection _on_data_collected_connection;
471
Atom _selection_atom;
473
guint _launcher_animation_timeout;
477
static const gchar introspection_xml[];
478
static GDBusInterfaceVTable interface_vtable;
480
static void OnBusAcquired(GDBusConnection* connection, const gchar* name, gpointer user_data);
481
static void OnNameAcquired(GDBusConnection* connection, const gchar* name, gpointer user_data);
482
static void OnNameLost(GDBusConnection* connection, const gchar* name, gpointer user_data);
483
static void handle_dbus_method_call(GDBusConnection* connection,
485
const gchar* object_path,
486
const gchar* interface_name,
487
const gchar* method_name,
488
GVariant* parameters,
489
GDBusMethodInvocation* invocation,
492
struct timespec _times[TIME_LAST];
494
bool _initial_drag_animation;
496
guint _ubus_handles[4];
498
nux::Color _background_color;
499
BaseTexturePtr launcher_sheen_;
502
AbstractIconRenderer::Ptr icon_renderer;
503
BackgroundEffectHelper bg_effect_helper_;
5
#include <Nux/BaseWindow.h>
6
#include "LauncherIcon.h"
7
#include "NuxGraphics/IOpenGLAsmShader.h"
8
#include "Nux/TimerProc.h"
12
class Launcher : public nux::View
15
Launcher(NUX_FILE_LINE_PROTO);
18
virtual long ProcessEvent(nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
19
virtual void Draw(nux::GraphicsContext& GfxContext, bool force_draw);
20
virtual void DrawContent(nux::GraphicsContext& GfxContext, bool force_draw);
21
virtual void PostDraw(nux::GraphicsContext& GfxContext, bool force_draw);
23
LauncherIcon* GetActiveTooltipIcon() {return m_ActiveTooltipIcon;}
24
LauncherIcon* GetActiveMenuIcon() {return m_ActiveMenuIcon;}
26
bool TooltipNotify(LauncherIcon* Icon);
27
bool MenuNotify(LauncherIcon* Icon);
29
void SetIconSize(int tile_size, int icon_size, nux::BaseWindow *parent);
30
void NotifyMenuTermination(LauncherIcon* Icon);
32
void SetModel (LauncherModel *model);
34
virtual void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
35
virtual void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
36
virtual void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
37
virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
38
virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
39
virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
40
virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);
54
} LauncherActionState;
56
void OnIconAdded (void *icon_pointer);
57
void OnIconRemoved (void *icon_pointer);
58
void OnOrderChanged ();
61
void OnIconNeedsRedraw (void *icon);
63
void FoldingCallback(void* v);
64
void RevealCallback(void* v);
66
void RenderIcon (nux::GraphicsContext& GfxContext, LauncherIcon* launcher_view);
67
void RenderIconImage(nux::GraphicsContext& GfxContext, LauncherIcon* launcher_view);
68
void UpdateIconXForm ();
69
LauncherIcon* MouseIconIntersection (int x, int y);
71
void MouseDownLogic ();
74
void SlideDown(float stepy, int mousedy);
75
void SlideUp(float stepy, int mousedy);
77
virtual void PreLayoutManagement();
78
virtual long PostLayoutManagement(long LayoutResult);
79
virtual void PositionChildLayout(float offsetX, float offsetY);
81
void OrderRevealedIcons();
82
void OrderFoldedIcons(int FocusIconIndex);
83
void ScheduleRevealAnimation ();
84
void ScheduleFoldAnimation ();
86
nux::HLayout* m_Layout;
89
LauncherIcon* m_ActiveTooltipIcon;
90
LauncherIcon* m_ActiveMenuIcon;
94
float _timer_intervals;
95
int _space_between_icons;
98
float _neg_folded_angle;
99
float _folded_z_distance;
100
float _launcher_top_y;
101
float _launcher_bottom_y;
102
LauncherState _launcher_state;
103
LauncherActionState _launcher_action_state;
104
LauncherIcon* _icon_under_mouse;
105
LauncherIcon* _icon_mouse_down;
107
int _icon_image_size;
108
int _icon_image_size_delta;
109
nux::BaseTexture* _icon_bkg_texture;
110
nux::BaseTexture* _icon_outline_texture;
114
nux::TimerFunctor* _folding_functor;
115
nux::TimerHandle _folding_timer_handle;
116
nux::TimerFunctor* _reveal_functor;
117
nux::TimerHandle _reveal_timer_handle;
119
nux::Matrix4 _view_matrix;
120
nux::Matrix4 _projection_matrix;
121
nux::Point2 _mouse_position;
122
nux::IntrusiveSP<nux::IOpenGLShaderProgram> _shader_program_uv_persp_correction;
123
nux::IntrusiveSP<nux::IOpenGLAsmShaderProgram> _AsmShaderProg;
124
nux::BaseTexture* m_RunningIndicator;
125
nux::BaseTexture* m_ActiveIndicator;
126
nux::AbstractPaintLayer* m_BackgroundLayer;
127
LauncherModel* _model;