Merge lp:~mhr3/unity/fix-856205 into lp:unity

Proposed by Michal Hruby
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1746
Proposed branch: lp:~mhr3/unity/fix-856205
Merge into: lp:unity
Diff against target: 124 lines (+58/-1)
3 files modified
manual-tests/Dash.txt (+13/-0)
plugins/unityshell/src/DashView.cpp (+39/-1)
plugins/unityshell/src/DashView.h (+6/-0)
To merge this branch: bzr merge lp:~mhr3/unity/fix-856205
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+83263@code.launchpad.net

This proposal supersedes a proposal from 2011-11-16.

Description of the change

Fixes bug #856205 by delaying activation of the first item in the model. Note that this requires also change to lenses (because currently they emit the SearchFinished signal before updating the model).

As didrocks informed me, this can't just go to stable branch without going to trunk, although I have much nicer fix in mind once we change some libunity internals.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote : Posted in a previous version of this proposal

I tested this quite thoroughly and it seems to work well. Code looks good too. Although there are some nitpicks:

 i) in ResetSearchState() Why reinterpret_cast and not static_cast?

 ii) in ResetSearchState() should we not g_source_remove (searching_timeout_id_); if the id != 0?

review: Approve
Revision history for this message
Tim Penhey (thumper) wrote :

Inside the unity code, can we please stay away from glib types?

Just use "unsigned" instead of "guint".

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

@Tim - that seems to be begging for trouble? This begs for 32/64 bit issues and nasty bool/gboolean issues both of which we've seen before.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Like the changes. Re-approved! :-)

review: Approve
Revision history for this message
Tim Penhey (thumper) wrote :

Due to lack of infrastructure for testing the timing issues here, I'm happy with a manual test.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'manual-tests/Dash.txt'
2--- manual-tests/Dash.txt 1970-01-01 00:00:00 +0000
3+++ manual-tests/Dash.txt 2011-11-28 20:56:25 +0000
4@@ -0,0 +1,13 @@
5+Dash search
6+-----------
7+This test makes sure that the right command is run when you search
8+using the dash. (see lp:856205)
9+
10+#. Press Alt+F2
11+#. Press 'g'. Make sure you see some command name (like gcc)
12+#. Quickly type 'edit<Enter>' - so you'd run 'gedit'.
13+
14+Outcome
15+ The dash disappears, and gedit is run. If nothing happens or the first
16+ command is run (in this case gcc), this test failed.
17+
18
19=== modified file 'plugins/unityshell/src/DashView.cpp'
20--- plugins/unityshell/src/DashView.cpp 2011-11-13 22:57:27 +0000
21+++ plugins/unityshell/src/DashView.cpp 2011-11-28 20:56:25 +0000
22@@ -49,6 +49,9 @@
23 : nux::View(NUX_TRACKER_LOCATION)
24 , active_lens_view_(0)
25 , last_activated_uri_("")
26+ , searching_timeout_id_(0)
27+ , search_in_progress_(false)
28+ , activate_on_finish_(false)
29 , visible_(false)
30
31 {
32@@ -69,6 +72,8 @@
33
34 DashView::~DashView()
35 {
36+ if (searching_timeout_id_)
37+ g_source_remove (searching_timeout_id_);
38 delete bg_layer_;
39 delete bg_darken_layer_;
40 }
41@@ -610,9 +615,32 @@
42 QueueDraw();
43 }
44
45+gboolean DashView::ResetSearchStateCb(gpointer data)
46+{
47+ DashView *self = static_cast<DashView*>(data);
48+
49+ self->search_in_progress_ = false;
50+ self->activate_on_finish_ = false;
51+ self->searching_timeout_id_ = 0;
52+
53+ return FALSE;
54+}
55+
56 void DashView::OnSearchChanged(std::string const& search_string)
57 {
58 LOG_DEBUG(logger) << "Search changed: " << search_string;
59+ if (active_lens_view_)
60+ {
61+ search_in_progress_ = true;
62+ // it isn't guaranteed that we get a SearchFinished signal, so we need
63+ // to make sure this isn't set even though we aren't doing any search
64+ if (searching_timeout_id_)
65+ {
66+ g_source_remove (searching_timeout_id_);
67+ }
68+ // 250ms for the Search method call, rest for the actual search
69+ searching_timeout_id_ = g_timeout_add (500, &DashView::ResetSearchStateCb, this);
70+ }
71 }
72
73 void DashView::OnLiveSearchReached(std::string const& search_string)
74@@ -676,7 +704,12 @@
75 void DashView::OnSearchFinished(std::string const& search_string)
76 {
77 if (search_bar_->search_string == search_string)
78+ {
79 search_bar_->SearchFinished();
80+ search_in_progress_ = false;
81+ if (activate_on_finish_)
82+ this->OnEntryActivated();
83+ }
84 }
85
86 void DashView::OnGlobalSearchFinished(std::string const& search_string)
87@@ -785,7 +818,12 @@
88 }
89 void DashView::OnEntryActivated()
90 {
91- active_lens_view_->ActivateFirst();
92+ if (!search_in_progress_)
93+ {
94+ active_lens_view_->ActivateFirst();
95+ }
96+ // delay the activation until we get the SearchFinished signal
97+ activate_on_finish_ = search_in_progress_;
98 }
99
100 // Keyboard navigation
101
102=== modified file 'plugins/unityshell/src/DashView.h'
103--- plugins/unityshell/src/DashView.h 2011-11-11 13:02:43 +0000
104+++ plugins/unityshell/src/DashView.h 2011-11-28 20:56:25 +0000
105@@ -103,6 +103,8 @@
106
107 nux::Area* KeyNavIteration(nux::KeyNavDirection direction);
108
109+ static gboolean ResetSearchStateCb(gpointer data);
110+
111 private:
112 UBusManager ubus_manager_;
113 FilesystemLenses lenses_;
114@@ -130,6 +132,10 @@
115 nux::ObjectPtr <nux::IOpenGLBaseTexture> bg_shine_texture_;
116
117 std::string last_activated_uri_;
118+ // we're passing this back to g_* functions, so we'll keep the g* type
119+ guint searching_timeout_id_;
120+ bool search_in_progress_;
121+ bool activate_on_finish_;
122
123 bool visible_;
124 };