Merge lp:~gordallott/unity/fix-results-keynav-scrolling into lp:unity

Proposed by Gord Allott
Status: Merged
Approved by: Neil J. Patel
Approved revision: no longer in the source branch.
Merged at revision: 1639
Proposed branch: lp:~gordallott/unity/fix-results-keynav-scrolling
Merge into: lp:unity
Diff against target: 180 lines (+87/-4)
4 files modified
plugins/unityshell/src/LensView.cpp (+67/-2)
plugins/unityshell/src/LensView.h (+4/-2)
plugins/unityshell/src/ResultViewGrid.cpp (+14/-0)
plugins/unityshell/src/UBusMessages.h (+2/-0)
To merge this branch: bzr merge lp:~gordallott/unity/fix-results-keynav-scrolling
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+77167@code.launchpad.net

Description of the change

So nux doesn't really support model views very well so this is a hack to get scrolling
on keynav working again, we'll fix it in a nicer way for P but yeah

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Makes sense for now, approved. Nice workaround :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/LensView.cpp'
2--- plugins/unityshell/src/LensView.cpp 2011-09-07 20:04:18 +0000
3+++ plugins/unityshell/src/LensView.cpp 2011-09-27 14:22:23 +0000
4@@ -26,6 +26,7 @@
5 #include "ResultRendererTile.h"
6 #include "ResultRendererHorizontalTile.h"
7 #include "UBusMessages.h"
8+#include "UBusWrapper.h"
9
10 namespace unity
11 {
12@@ -37,6 +38,45 @@
13 nux::logging::Logger logger("unity.dash.lensview");
14 }
15
16+ // this is so we can access some protected members in scrollview
17+class LensScrollView: public nux::ScrollView
18+{
19+public:
20+ LensScrollView(NUX_FILE_LINE_DECL)
21+ : nux::ScrollView(NUX_FILE_LINE_PARAM)
22+ {
23+
24+ }
25+
26+ void ScrollToPosition(nux::Geometry & position)
27+ {
28+ // much of this code is copied from Nux/ScrollView.cpp
29+ int child_y = position.y - GetGeometry ().y;
30+ int child_y_diff = child_y - abs (_delta_y);
31+
32+ if (child_y_diff + position.height < GetGeometry ().height && child_y_diff >= 0)
33+ {
34+ return;
35+ }
36+
37+ if (child_y_diff < 0)
38+ {
39+ ScrollUp (1, abs (child_y_diff));
40+ }
41+ else
42+ {
43+ int size = child_y_diff - GetGeometry ().height;
44+
45+ // always keeps the top of a view on the screen
46+ size += position.height;
47+
48+ ScrollDown (1, size);
49+ }
50+ }
51+
52+};
53+
54+
55 NUX_IMPLEMENT_OBJECT_TYPE(LensView);
56
57 LensView::LensView()
58@@ -59,12 +99,37 @@
59 SetupResults();
60 SetupFilters();
61
62- PlacesStyle::GetDefault()->columns_changed.connect(sigc::mem_fun(this, &LensView::OnColumnsChanged));
63+ PlacesStyle::GetDefault()->columns_changed.connect(sigc::mem_fun(this, &LensView::OnColumnsChanged));
64
65 lens_->connected.changed.connect([&](bool is_connected) { if (is_connected) initial_activation_ = true; });
66 search_string.changed.connect([&](std::string const& search) { lens_->Search(search); });
67 filters_expanded.changed.connect([&](bool expanded) { fscroll_view_->SetVisible(expanded); QueueRelayout(); OnColumnsChanged(); });
68 active.changed.connect(sigc::mem_fun(this, &LensView::OnActiveChanged));
69+
70+ ubus_.RegisterInterest(UBUS_RESULT_VIEW_KEYNAV_CHANGED, [this] (GVariant* data) {
71+ // we get this signal when a result view keynav changes,
72+ // its a bad way of doing this but nux ABI needs to be broken
73+ // to do it properly
74+ nux::Geometry focused_pos;
75+ g_variant_get (data, "(iiii)", &focused_pos.x, &focused_pos.y, &focused_pos.width, &focused_pos.height);
76+
77+ for (auto it = categories_.begin(); it != categories_.end(); it++)
78+ {
79+ if ((*it)->GetLayout() != nullptr)
80+ {
81+ nux::View *child = (*it)->GetChildView();
82+ if (child->HasKeyFocus())
83+ {
84+ focused_pos.x += child->GetGeometry().x;
85+ focused_pos.y += child->GetGeometry().y - 30;
86+ focused_pos.height += 30;
87+ static_cast<LensScrollView *>(scroll_view_)->ScrollToPosition(focused_pos);
88+ break;
89+ }
90+ }
91+ }
92+ });
93+
94 }
95
96 LensView::~LensView()
97@@ -77,7 +142,7 @@
98 {
99 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
100
101- scroll_view_ = new nux::ScrollView(NUX_TRACKER_LOCATION);
102+ scroll_view_ = new LensScrollView(NUX_TRACKER_LOCATION);
103 scroll_view_->EnableVerticalScrollBar(true);
104 scroll_view_->EnableHorizontalScrollBar(false);
105 layout_->AddView(scroll_view_);
106
107=== modified file 'plugins/unityshell/src/LensView.h'
108--- plugins/unityshell/src/LensView.h 2011-08-25 10:18:58 +0000
109+++ plugins/unityshell/src/LensView.h 2011-09-27 14:22:23 +0000
110@@ -51,7 +51,7 @@
111 virtual ~LensView();
112
113 Lens::Ptr lens() const;
114-
115+
116 virtual void ActivateFirst();
117
118 nux::Property<std::string> search_string;
119@@ -82,7 +82,7 @@
120 virtual long ProcessEvent(nux::IEvent& ievent, long traverse_info, long event_info);
121 virtual void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);
122 virtual void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw);
123-
124+
125 virtual bool AcceptKeyNavFocus();
126 virtual const gchar* GetName();
127 virtual void AddProperties(GVariantBuilder* builder);
128@@ -102,6 +102,8 @@
129 FilterBar* filter_bar_;
130
131 guint fix_renderering_id_;
132+
133+ UBusManager ubus_;
134 };
135
136
137
138=== modified file 'plugins/unityshell/src/ResultViewGrid.cpp'
139--- plugins/unityshell/src/ResultViewGrid.cpp 2011-09-26 10:41:01 +0000
140+++ plugins/unityshell/src/ResultViewGrid.cpp 2011-09-27 14:22:23 +0000
141@@ -467,6 +467,13 @@
142 selected_index_ = std::max(0, selected_index_);
143 selected_index_ = std::min(static_cast<int>(results_.size() - 1), selected_index_);
144 focused_uri_ = results_[selected_index_].uri;
145+
146+ int focused_x = (renderer_->width + horizontal_spacing) * (selected_index_ % items_per_row);
147+ int focused_y = (renderer_->height + vertical_spacing) * (selected_index_ / items_per_row);
148+
149+ ubus_.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
150+ g_variant_new("(iiii)", focused_x, focused_y, renderer_->width(), renderer_->height()));
151+
152 NeedRedraw();
153 }
154
155@@ -484,6 +491,13 @@
156 focused_uri_ = results_.front().uri;
157 selected_index_ = 0;
158 NeedRedraw();
159+
160+ int items_per_row = GetItemsPerRow();
161+ int focused_x = (renderer_->width + horizontal_spacing) * (selected_index_ % items_per_row);
162+ int focused_y = (renderer_->height + vertical_spacing) * (selected_index_ / items_per_row);
163+
164+ ubus_.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
165+ g_variant_new("(iiii)", focused_x, focused_y, renderer_->width(), renderer_->height()));
166 }
167 else
168 {
169
170=== modified file 'plugins/unityshell/src/UBusMessages.h'
171--- plugins/unityshell/src/UBusMessages.h 2011-09-22 09:46:55 +0000
172+++ plugins/unityshell/src/UBusMessages.h 2011-09-27 14:22:23 +0000
173@@ -68,5 +68,7 @@
174 #define UBUS_BACKGROUND_REQUEST_COLOUR_EMIT "REQUEST_BACKGROUND_COLOUR_EMIT"
175
176 #define UBUS_DASH_SIZE_CHANGED "DASH_SIZE_CHANGED"
177+// FIXME - fix the nux focus api so we don't need this
178+#define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED"
179
180 #endif // UBUS_MESSAGES_H