Merge lp:~jamalta/unity/683261-autohide-quicklist into lp:unity

Proposed by Jamal Fanaian
Status: Merged
Merged at revision: 696
Proposed branch: lp:~jamalta/unity/683261-autohide-quicklist
Merge into: lp:unity
Diff against target: 557 lines (+233/-125)
8 files modified
src/Launcher.cpp (+19/-18)
src/Launcher.h (+2/-6)
src/LauncherIcon.cpp (+14/-32)
src/LauncherIcon.h (+0/-3)
src/QuicklistManager.cpp (+109/-0)
src/QuicklistManager.h (+52/-0)
src/QuicklistView.cpp (+34/-66)
src/QuicklistView.h (+3/-0)
To merge this branch: bzr merge lp:~jamalta/unity/683261-autohide-quicklist
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+43288@code.launchpad.net

Description of the change

Created QuicklistManager which is now responsible for handling Hiding and Showing a QuicklistView. Launcher uses QuicklistManager to figure out whether a QuicklistView is currently open before autohiding.

To post a comment you must log in.
Revision history for this message
Jason Smith (jassmith) wrote :

+2

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Launcher.cpp'
2--- src/Launcher.cpp 2010-12-09 13:30:37 +0000
3+++ src/Launcher.cpp 2010-12-09 20:57:22 +0000
4@@ -35,6 +35,7 @@
5 #include "Launcher.h"
6 #include "LauncherIcon.h"
7 #include "LauncherModel.h"
8+#include "QuicklistManager.h"
9 #include "QuicklistView.h"
10
11 #define ANIM_DURATION_SHORT 125
12@@ -190,6 +191,9 @@
13 OnMouseMove.connect(sigc::mem_fun(this, &Launcher::RecvMouseMove));
14 OnMouseWheel.connect(sigc::mem_fun(this, &Launcher::RecvMouseWheel));
15
16+ QuicklistManager::Default ()->quicklist_opened.connect (sigc::mem_fun(this, &Launcher::RecvQuicklistOpened));
17+ QuicklistManager::Default ()->quicklist_closed.connect (sigc::mem_fun(this, &Launcher::RecvQuicklistClosed));
18+
19 m_ActiveTooltipIcon = NULL;
20 m_ActiveMenuIcon = NULL;
21
22@@ -843,7 +847,7 @@
23 void
24 Launcher::EnsureHiddenState ()
25 {
26- if (!_mouse_inside_trigger && !_mouse_inside_launcher && _window_over_launcher)
27+ if (!_mouse_inside_trigger && !_mouse_inside_launcher && _window_over_launcher && !QuicklistManager::Default ()->Current())
28 SetHidden (true);
29 else
30 SetHidden (false);
31@@ -1615,6 +1619,20 @@
32 {
33 }
34
35+void Launcher::RecvQuicklistOpened (QuicklistView *quicklist)
36+{
37+ EventLogic ();
38+ EnsureAnimation ();
39+}
40+
41+void Launcher::RecvQuicklistClosed (QuicklistView *quicklist)
42+{
43+ SetupAutohideTimer ();
44+
45+ EventLogic ();
46+ EnsureAnimation ();
47+}
48+
49 void Launcher::EventLogic ()
50 {
51 if (_launcher_action_state == ACTION_DRAG_LAUNCHER)
52@@ -1954,20 +1972,3 @@
53 // glEnd();
54 }
55
56-void Launcher::SetActiveQuicklist (QuicklistView *quicklist)
57-{
58- // Assert: _active_quicklist should be 0
59- _active_quicklist = quicklist;
60-}
61-
62-QuicklistView *Launcher::GetActiveQuicklist ()
63-{
64- return _active_quicklist;
65-}
66-
67-void Launcher::CancelActiveQuicklist (QuicklistView *quicklist)
68-{
69- if (_active_quicklist == quicklist)
70- _active_quicklist = 0;
71-}
72-
73
74=== modified file 'src/Launcher.h'
75--- src/Launcher.h 2010-12-07 16:05:52 +0000
76+++ src/Launcher.h 2010-12-09 20:57:22 +0000
77@@ -73,12 +73,8 @@
78 virtual void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
79 virtual void RecvMouseWheel(int x, int y, int wheel_delta, unsigned long button_flags, unsigned long key_flags);
80
81- //! Called by LauncherIcon to signal that a Quicklist is becoming active.
82- void SetActiveQuicklist (QuicklistView *quicklist);
83- //! Get the active qicklist
84- QuicklistView *GetActiveQuicklist ();
85- //! Called by LauncherIcon to signal that a Quicklist is becoming unactive.
86- void CancelActiveQuicklist (QuicklistView *quicklist);
87+ virtual void RecvQuicklistOpened (QuicklistView *quicklist);
88+ virtual void RecvQuicklistClosed (QuicklistView *quicklist);
89
90 protected:
91 // Introspectable methods
92
93=== modified file 'src/LauncherIcon.cpp'
94--- src/LauncherIcon.cpp 2010-12-07 23:19:18 +0000
95+++ src/LauncherIcon.cpp 2010-12-09 20:57:22 +0000
96@@ -31,6 +31,7 @@
97 #include "LauncherIcon.h"
98 #include "Launcher.h"
99
100+#include "QuicklistManager.h"
101 #include "QuicklistMenuItem.h"
102 #include "QuicklistMenuItemLabel.h"
103 #include "QuicklistMenuItemSeparator.h"
104@@ -66,9 +67,9 @@
105 _sort_priority = 0;
106
107 _quicklist = new QuicklistView ();
108- _quicklist->sigVisible.connect (sigc::mem_fun (this, &LauncherIcon::RecvShowQuicklist));
109- _quicklist->sigHidden.connect (sigc::mem_fun (this, &LauncherIcon::RecvHideQuicklist));
110 _quicklist_is_initialized = false;
111+
112+ QuicklistManager::Default ()->RegisterQuicklist (_quicklist);
113
114 // Add to introspection
115 AddChild (_quicklist);
116@@ -292,7 +293,7 @@
117 void
118 LauncherIcon::RecvMouseEnter ()
119 {
120- if (_launcher->GetActiveQuicklist ())
121+ if (QuicklistManager::Default ()->Current ())
122 {
123 // A quicklist is active
124 return;
125@@ -318,24 +319,21 @@
126 {
127 if (button == 3)
128 {
129- if (_launcher->GetActiveQuicklist () == _quicklist)
130- {
131- // this quicklist is already active
132- return;
133- }
134-
135- if (_launcher->GetActiveQuicklist ())
136- {
137+ if (QuicklistManager::Default ()->Current ())
138+ {
139+ // We probably should let QuicklistManager deal with this case...
140+ QuicklistManager::Default ()->HideQuicklist (QuicklistManager::Default ()->Current());
141+
142 // Hide the active quicklist. This will prevent it from Ungrabing the pointer in
143 // QuicklistView::RecvMouseDownOutsideOfQuicklist or void QuicklistView::RecvMouseClick.
144 // So the new quicklist that is about to be set as active will keep the grab of the pointer.
145 // Also disable theinput window.
146- _launcher->GetActiveQuicklist ()->EnableInputWindow (false);
147- _launcher->GetActiveQuicklist ()->CaptureMouseDownAnyWhereElse (false);
148+ //QuicklistManager::Default ()->Current ()->EnableInputWindow (false);
149+ //QuicklistManager::Default ()->Current ()->CaptureMouseDownAnyWhereElse (false);
150 // This call must be last, because after, _launcher->GetActiveQuicklist () will return Null.
151 // the launcher listen to the sigHidden signal emitted by the BaseWindow when it becomes invisible
152 // and it set the active window to Null.
153- _launcher->GetActiveQuicklist ()->ShowWindow (false);
154+ //QuicklistManager::Default ()->Current ()->ShowWindow (false);
155 }
156
157 _tooltip->ShowWindow (false);
158@@ -378,14 +376,8 @@
159
160 int tip_x = _launcher->GetBaseWidth () + 1; //icon_x + icon_w;
161 int tip_y = _center.y;
162- _quicklist->ShowQuicklistWithTipAt (tip_x, tip_y);
163-
164- _quicklist->EnableInputWindow (true, 1);
165- _quicklist->GrabPointer ();
166-
167+ QuicklistManager::Default ()->ShowQuicklist (_quicklist, tip_x, tip_y);
168 nux::GetWindowCompositor ().SetAlwaysOnFrontWindow (_quicklist);
169-
170- _quicklist->NeedRedraw ();
171 }
172 }
173
174@@ -398,16 +390,6 @@
175 }
176 }
177
178-void LauncherIcon::RecvShowQuicklist (nux::BaseWindow *quicklist)
179-{
180- _launcher->SetActiveQuicklist (_quicklist);
181-}
182-
183-void LauncherIcon::RecvHideQuicklist (nux::BaseWindow *quicklist)
184-{
185- _launcher->CancelActiveQuicklist (_quicklist);
186-}
187-
188 void LauncherIcon::HideTooltip ()
189 {
190 _tooltip->ShowWindow (false);
191@@ -437,7 +419,7 @@
192 int tip_y = _center.y;
193
194 if (_quicklist->IsVisible ())
195- _quicklist->ShowQuicklistWithTipAt (tip_x, tip_y);
196+ QuicklistManager::Default ()->ShowQuicklist (_quicklist, tip_x, tip_y);
197 else if (_tooltip->IsVisible ())
198 _tooltip->ShowTooltipWithTipAt (tip_x, tip_y);
199
200
201=== modified file 'src/LauncherIcon.h'
202--- src/LauncherIcon.h 2010-12-07 23:19:18 +0000
203+++ src/LauncherIcon.h 2010-12-09 20:57:22 +0000
204@@ -80,9 +80,6 @@
205 void RecvMouseDown (int button);
206 void RecvMouseUp (int button);
207
208- void RecvShowQuicklist (nux::BaseWindow *quicklist);
209- void RecvHideQuicklist (nux::BaseWindow *quicklist);
210-
211 void HideTooltip ();
212
213 void SetCenter (nux::Point3 center);
214
215=== added file 'src/QuicklistManager.cpp'
216--- src/QuicklistManager.cpp 1970-01-01 00:00:00 +0000
217+++ src/QuicklistManager.cpp 2010-12-09 20:57:22 +0000
218@@ -0,0 +1,109 @@
219+/*
220+ * Copyright (C) 2010 Canonical Ltd
221+ *
222+ * This program is free software: you can redistribute it and/or modify
223+ * it under the terms of the GNU General Public License version 3 as
224+ * published by the Free Software Foundation.
225+ *
226+ * This program is distributed in the hope that it will be useful,
227+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
228+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
229+ * GNU General Public License for more details.
230+ *
231+ * You should have received a copy of the GNU General Public License
232+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
233+ *
234+ * Authored by: Jamal Fanaian <j@jamalfanaian.com>
235+ */
236+
237+#include "Nux/Nux.h"
238+#include "Nux/BaseWindow.h"
239+#include "Nux/VLayout.h"
240+#include "Nux/WindowCompositor.h"
241+#include "QuicklistView.h"
242+#include "QuicklistManager.h"
243+
244+QuicklistManager * QuicklistManager::_default = 0;
245+
246+/* static */
247+QuicklistManager *QuicklistManager::Default ()
248+{
249+ if (!_default)
250+ _default = new QuicklistManager ();
251+ return _default;
252+}
253+
254+QuicklistManager::QuicklistManager ()
255+{
256+ _current_quicklist = 0;
257+}
258+
259+QuicklistManager::~QuicklistManager ()
260+{
261+}
262+
263+QuicklistView *QuicklistManager::Current ()
264+{
265+ return _current_quicklist;
266+}
267+
268+void QuicklistManager::RegisterQuicklist (QuicklistView *quicklist)
269+{
270+ std::list<QuicklistView*>::iterator it;
271+
272+ if (std::find (_quicklist_list.begin(), _quicklist_list.end(), quicklist) != _quicklist_list.end()) {
273+ // quicklist has already been registered
274+ g_warning ("Attempted to register a quicklist that was previously registered");
275+ return;
276+ }
277+
278+ _quicklist_list.push_back (quicklist);
279+
280+ quicklist->sigVisible.connect (sigc::mem_fun (this, &QuicklistManager::RecvShowQuicklist));
281+ quicklist->sigHidden.connect (sigc::mem_fun (this, &QuicklistManager::RecvHideQuicklist));
282+}
283+
284+void QuicklistManager::ShowQuicklist (QuicklistView *quicklist, int tip_x,
285+ int tip_y, bool hide_existing_if_open)
286+{
287+ if (_current_quicklist == quicklist)
288+ {
289+ // this quicklist is already active
290+ // do we want to still redraw in case the position has changed?
291+ return;
292+ }
293+
294+ if (hide_existing_if_open && _current_quicklist)
295+ {
296+ HideQuicklist (_current_quicklist);
297+ }
298+
299+ quicklist->ShowQuicklistWithTipAt (tip_x, tip_y);
300+}
301+
302+void QuicklistManager::HideQuicklist (QuicklistView *quicklist)
303+{
304+ quicklist->Hide();
305+}
306+
307+void QuicklistManager::RecvShowQuicklist (nux::BaseWindow *window)
308+{
309+ QuicklistView *quicklist = (QuicklistView*) window;
310+
311+ _current_quicklist = quicklist;
312+
313+ quicklist_opened.emit (quicklist);
314+}
315+
316+void QuicklistManager::RecvHideQuicklist (nux::BaseWindow *window)
317+{
318+ QuicklistView *quicklist = (QuicklistView*) window;
319+
320+ if (_current_quicklist == quicklist)
321+ {
322+ _current_quicklist = 0;
323+ }
324+
325+ quicklist_closed.emit (quicklist);
326+}
327+
328
329=== added file 'src/QuicklistManager.h'
330--- src/QuicklistManager.h 1970-01-01 00:00:00 +0000
331+++ src/QuicklistManager.h 2010-12-09 20:57:22 +0000
332@@ -0,0 +1,52 @@
333+/*
334+ * Copyright (C) 2010 Canonical Ltd
335+ *
336+ * This program is free software: you can redistribute it and/or modify
337+ * it under the terms of the GNU General Public License version 3 as
338+ * published by the Free Software Foundation.
339+ *
340+ * This program is distributed in the hope that it will be useful,
341+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
342+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
343+ * GNU General Public License for more details.
344+ *
345+ * You should have received a copy of the GNU General Public License
346+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
347+ *
348+ * Authored by: Jamal Fanaian <j@jamalfanaian.com>
349+ */
350+
351+#ifndef QUICKLISTMANAGER_H
352+#define QUICKLISTMANAGER_H
353+
354+class QuicklistManager : public sigc::trackable
355+{
356+public:
357+ static QuicklistManager *Default ();
358+
359+ QuicklistManager ();
360+
361+ ~QuicklistManager ();
362+
363+ QuicklistView *Current ();
364+
365+ void RegisterQuicklist (QuicklistView *quicklist);
366+ void ShowQuicklist (QuicklistView *quicklist, int tip_x, int tip_y, bool hide_existing_if_open = true);
367+ void HideQuicklist (QuicklistView *quicklist);
368+
369+ void RecvShowQuicklist (nux::BaseWindow *window);
370+ void RecvHideQuicklist (nux::BaseWindow *window);
371+
372+ sigc::signal<void, QuicklistView*> quicklist_opened;
373+ sigc::signal<void, QuicklistView*> quicklist_closed;
374+
375+private:
376+ static QuicklistManager *_default;
377+
378+ std::list<QuicklistView*> _quicklist_list;
379+ QuicklistView *_current_quicklist;
380+
381+};
382+
383+#endif
384+
385
386=== modified file 'src/QuicklistView.cpp'
387--- src/QuicklistView.cpp 2010-12-09 10:55:58 +0000
388+++ src/QuicklistView.cpp 2010-12-09 20:57:22 +0000
389@@ -151,7 +151,7 @@
390 SetBaseX (x);
391 SetBaseY (y);
392
393- ShowWindow (true);
394+ Show ();
395 }
396
397 void QuicklistView::ShowWindow (bool b, bool start_modal)
398@@ -159,6 +159,31 @@
399 BaseWindow::ShowWindow (b, start_modal);
400 }
401
402+void QuicklistView::Show ()
403+{
404+ if (!IsVisible())
405+ {
406+ // FIXME: ShowWindow shouldn't need to be called first
407+ ShowWindow (true);
408+ EnableInputWindow (true, 1);
409+ GrabPointer ();
410+ NeedRedraw ();
411+ }
412+}
413+
414+void QuicklistView::Hide ()
415+{
416+ if (IsVisible() && !_enable_quicklist_for_testing)
417+ {
418+ CancelItemsPrelightStatus ();
419+ CaptureMouseDownAnyWhereElse (false);
420+ ForceStopFocus (1, 1);
421+ UnGrabPointer ();
422+ EnableInputWindow (false);
423+ ShowWindow (false);
424+ }
425+}
426+
427 long QuicklistView::ProcessEvent (nux::IEvent& ievent, long TraverseInfo, long ProcessEventInfo)
428 {
429 long ret = TraverseInfo;
430@@ -198,36 +223,14 @@
431 else
432 {
433 _mouse_down = false;
434- if (IsVisible ())
435- {
436- if (!_enable_quicklist_for_testing)
437- {
438- CancelItemsPrelightStatus ();
439- CaptureMouseDownAnyWhereElse (false);
440- ForceStopFocus (1, 1);
441- UnGrabPointer ();
442- EnableInputWindow (false);
443- ShowWindow (false);
444- }
445- }
446+ Hide ();
447 return nux::eMouseEventSolved;
448 }
449 }
450 else if ((ievent.e_event == nux::NUX_MOUSE_RELEASED) && _mouse_down)
451 {
452 _mouse_down = false;
453- if (IsVisible ())
454- {
455- if (!_enable_quicklist_for_testing)
456- {
457- CancelItemsPrelightStatus ();
458- CaptureMouseDownAnyWhereElse (false);
459- ForceStopFocus (1, 1);
460- UnGrabPointer ();
461- EnableInputWindow (false);
462- ShowWindow (false);
463- }
464- }
465+ Hide ();
466 return nux::eMouseEventSolved;
467 }
468
469@@ -418,15 +421,7 @@
470 // Check if the mouse was released over an item and emit the signal
471 CheckAndEmitItemSignal (x + item->GetBaseX (), y + item->GetBaseY ());
472
473- if (!_enable_quicklist_for_testing)
474- {
475- CancelItemsPrelightStatus ();
476- CaptureMouseDownAnyWhereElse (false);
477- ForceStopFocus (1, 1);
478- UnGrabPointer ();
479- EnableInputWindow (false);
480- ShowWindow (false);
481- }
482+ Hide ();
483 }
484 }
485
486@@ -474,17 +469,9 @@
487 {
488 // Check if the mouse was released over an item and emit the signal
489 CheckAndEmitItemSignal (x + item->GetBaseX (), y + item->GetBaseY ());
490-
491- if (!_enable_quicklist_for_testing)
492- {
493- CancelItemsPrelightStatus ();
494- CaptureMouseDownAnyWhereElse (false);
495- ForceStopFocus (1, 1);
496- UnGrabPointer ();
497- EnableInputWindow (false);
498- ShowWindow (false);
499- }
500- }
501+
502+ Hide ();
503+ }
504 }
505
506 void QuicklistView::CancelItemsPrelightStatus ()
507@@ -570,15 +557,7 @@
508 {
509 if (IsVisible ())
510 {
511- if (!_enable_quicklist_for_testing)
512- {
513- CancelItemsPrelightStatus ();
514- CaptureMouseDownAnyWhereElse (false);
515- ForceStopFocus (1, 1);
516- UnGrabPointer ();
517- EnableInputWindow (false);
518- ShowWindow (false);
519- }
520+ Hide ();
521 }
522 }
523
524@@ -594,18 +573,7 @@
525
526 void QuicklistView::RecvMouseDownOutsideOfQuicklist (int x, int y, unsigned long button_flags, unsigned long key_flags)
527 {
528- if (IsVisible ())
529- {
530- if (!_enable_quicklist_for_testing)
531- {
532- CancelItemsPrelightStatus ();
533- CaptureMouseDownAnyWhereElse (false);
534- ForceStopFocus (1, 1);
535- UnGrabPointer ();
536- EnableInputWindow (false);
537- ShowWindow (false);
538- }
539- }
540+ Hide ();
541 }
542
543 void QuicklistView::RemoveAllMenuItem ()
544
545=== modified file 'src/QuicklistView.h'
546--- src/QuicklistView.h 2010-12-09 10:55:58 +0000
547+++ src/QuicklistView.h 2010-12-09 20:57:22 +0000
548@@ -80,6 +80,9 @@
549
550 void ShowQuicklistWithTipAt (int anchor_tip_x, int anchor_tip_y);
551 virtual void ShowWindow (bool b, bool StartModal = false);
552+
553+ void Show ();
554+ void Hide ();
555
556 int GetNumItems ();
557 QuicklistMenuItem* GetNthItems (int index);