~canonical-dx-team/unity/unity.fix-ql-losing-focus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2010 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Jason Smith <jason.smith@canonical.com>
 * 
 */

#ifndef LAUNCHERICON_H
#define LAUNCHERICON_H

#include <Nux/Nux.h>
#include <Nux/BaseWindow.h>
#include <NuxCore/Math/MathInc.h>

#include <sigc++/trackable.h>
#include <sigc++/signal.h>
#include <sigc++/functors/ptr_fun.h>
#include <sigc++/functors/mem_fun.h>

#include <gtk/gtk.h>
#include <libdbusmenu-glib/client.h>
#include <libdbusmenu-glib/menuitem.h>

#include "Tooltip.h"
#include "QuicklistView.h"
#include "Introspectable.h"
#include "Launcher.h"
#include "LauncherEntryRemote.h"

class Launcher;
class QuicklistView;

class LauncherIcon : public Introspectable, public nux::InitiallyUnownedObject
{
  NUX_DECLARE_OBJECT_TYPE (LauncherIcon, nux::InitiallyUnownedObject);
public:
    typedef enum
    {
      TYPE_NONE,
      TYPE_BEGIN,
      TYPE_FAVORITE,
      TYPE_APPLICATION,
      TYPE_EXPO,
      TYPE_PLACE,
      TYPE_DEVICE,
      TYPE_TRASH,
      TYPE_END,
    } IconType;

    typedef enum
    {
      QUIRK_VISIBLE,
      QUIRK_ACTIVE,
      QUIRK_RUNNING,
      QUIRK_URGENT,
      QUIRK_PRESENTED,
      QUIRK_STARTING,
      QUIRK_SHIMMER,
      QUIRK_CENTER_SAVED,
      QUIRK_PROGRESS,
      QUIRK_DROP_PRELIGHT,
      QUIRK_DROP_DIM,
      
      QUIRK_LAST,
    } Quirk;

    LauncherIcon(Launcher* launcher);
    virtual ~LauncherIcon();

    Launcher* GetLauncher () {return _launcher;};

    void SetTooltipText (const TCHAR* text);
    
    nux::NString GetTooltipText ();
    
    void    SetShortcut (guint64 shortcut);
    guint64 GetShortcut ();
    
    void RecvMouseEnter ();
    void RecvMouseLeave ();
    void RecvMouseDown (int button);
    void RecvMouseUp (int button);
    
    void HideTooltip ();
    void OpenQuicklist (bool default_to_first_item = false);

    void        SetCenter (nux::Point3 center);
    nux::Point3 GetCenter ();

    void Activate ();
    void OpenInstance ();

    void SaveCenter ();
    
    int SortPriority ();
    
    int RelatedWindows ();
    
    bool HasVisibleWindow ();
    
    float PresentUrgency ();
    
    float GetProgress ();
    
    void SetEmblemIconName (const char *name);
    void SetEmblemText (const char *text);
    
    void DeleteEmblem ();
    
    bool GetQuirk (Quirk quirk);
    struct timespec GetQuirkTime (Quirk quirk);
    
    IconType Type ();
    
    virtual nux::Color BackgroundColor ();
    virtual nux::Color GlowColor ();
    
    const gchar * RemoteUri () { return GetRemoteUri (); }
    
    nux::BaseTexture * TextureForSize (int size);
    
    nux::BaseTexture * Emblem ();
    
    std::list<DbusmenuMenuitem *> Menus ();
    
    void InsertEntryRemote (LauncherEntryRemote *remote);
    void RemoveEntryRemote (LauncherEntryRemote *remote);
    
    nux::DndAction QueryAcceptDrop (std::list<char *> paths) { return OnQueryAcceptDrop (paths); }
    void AcceptDrop (std::list<char *> paths) { return OnAcceptDrop (paths); }
    void SendDndEnter () { OnDndEnter (); }
    void SendDndLeave () { OnDndLeave (); }
    
    sigc::signal<void, int> MouseDown;
    sigc::signal<void, int> MouseUp;
    sigc::signal<void>      MouseEnter;
    sigc::signal<void>      MouseLeave;
    sigc::signal<void, int> MouseClick;
    
    sigc::signal<void, LauncherIcon *> show;
    sigc::signal<void, LauncherIcon *> hide;
    sigc::signal<void, LauncherIcon *> remove;
    sigc::signal<void, LauncherIcon *> needs_redraw;
protected:
    const gchar * GetName ();
    void AddProperties (GVariantBuilder *builder);

    void SetQuirk (Quirk quirk, bool value);

    void UpdateQuirkTimeDelayed (guint ms, Quirk quirk);
    void UpdateQuirkTime (Quirk quirk);
    void ResetQuirkTime (Quirk quirk);

    void SetRelatedWindows (int windows);
    void Remove ();
    
    void SetProgress (float progress);
    
    void SetHasVisibleWindow (bool val);
    
    void Present (float urgency, int length);
    void Unpresent ();
    
    void SetIconType (IconType type);
    void SetSortPriority (int priority);

    void SetEmblem (nux::BaseTexture *emblem);
    void SetSuperkeyLabel (nux::BaseTexture* label);
    nux::BaseTexture* GetSuperkeyLabel ();

    virtual std::list<DbusmenuMenuitem *> GetMenus ();
    virtual nux::BaseTexture * GetTextureForSize (int size) = 0;
    
    virtual void OnCenterStabilized (nux::Point3 center) {}
    
    virtual const gchar * GetRemoteUri () { return 0; }
    
    virtual nux::DndAction OnQueryAcceptDrop (std::list<char *> files) { return nux::DNDACTION_NONE; }
    virtual void OnAcceptDrop (std::list<char *> files) {}
    virtual void OnDndEnter () {}
    virtual void OnDndLeave () {}
    
    virtual void ActivateLauncherIcon () {}
    virtual void OpenInstanceLauncherIcon () {}

    nux::BaseTexture * TextureFromGtkTheme (const char *name, int size);
    nux::BaseTexture * TextureFromPath     (const char *name, int size);

    void OnRemoteEmblemChanged    (LauncherEntryRemote *remote);
    void OnRemoteCountChanged     (LauncherEntryRemote *remote);
    void OnRemoteProgressChanged  (LauncherEntryRemote *remote);
    void OnRemoteQuicklistChanged (LauncherEntryRemote *remote);

    void OnRemoteEmblemVisibleChanged   (LauncherEntryRemote *remote);
    void OnRemoteCountVisibleChanged    (LauncherEntryRemote *remote);
    void OnRemoteProgressVisibleChanged (LauncherEntryRemote *remote);

    nux::NString m_TooltipText;
    //! the window this icon belong too.
    nux::BaseWindow* m_Window;
    Launcher* _launcher;

    std::map<std::string, nux::Vector4*> _xform_coords;
    bool          _mouse_inside;
    float         _folding_angle;

    nux::Tooltip *_tooltip;
    QuicklistView *_quicklist;

    static nux::Tooltip *_current_tooltip;
    static QuicklistView *_current_quicklist;


    friend class Launcher;
    friend class LauncherController;
    friend class LauncherModel;

private:
    typedef struct
    {
      LauncherIcon *self;
      Quirk quirk;
    } DelayedUpdateArg;

    static void ChildRealized (DbusmenuMenuitem *newitem, QuicklistView *quicklist);
    static void RootChanged (DbusmenuClient * client, DbusmenuMenuitem *newroot, QuicklistView *quicklist);
    static gboolean OnPresentTimeout (gpointer data);
    static gboolean OnCenterTimeout (gpointer data);
    static gboolean OnDelayedUpdateTimeout (gpointer data);

    void ColorForIcon (GdkPixbuf *pixbuf, nux::Color &background, nux::Color &glow);

    nux::Color       _background_color;
    nux::Color       _glow_color;
    int              _sort_priority;
    int              _related_windows;
    float            _present_urgency;
    float            _progress;
    guint            _present_time_handle;
    guint            _center_stabilize_handle;
    bool             _quicklist_is_initialized;
    bool             _has_visible_window;
    
    gint64           _shortcut;
    
    nux::Point3      _center;
    nux::Point3      _last_stable;
    nux::Point3      _saved_center;
    IconType         _icon_type;
    
    nux::BaseTexture* _emblem;
    nux::BaseTexture* _superkey_label;
    
    bool             _quirks[QUIRK_LAST];
    struct timespec  _quirk_times[QUIRK_LAST];
    
    std::list<LauncherEntryRemote *> _entry_list;
};

#endif // LAUNCHERICON_H