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
=== modified file 'plugins/unityshell/src/LensView.cpp'
--- plugins/unityshell/src/LensView.cpp 2011-09-07 20:04:18 +0000
+++ plugins/unityshell/src/LensView.cpp 2011-09-27 14:22:23 +0000
@@ -26,6 +26,7 @@
26#include "ResultRendererTile.h"26#include "ResultRendererTile.h"
27#include "ResultRendererHorizontalTile.h"27#include "ResultRendererHorizontalTile.h"
28#include "UBusMessages.h"28#include "UBusMessages.h"
29#include "UBusWrapper.h"
2930
30namespace unity31namespace unity
31{32{
@@ -37,6 +38,45 @@
37nux::logging::Logger logger("unity.dash.lensview");38nux::logging::Logger logger("unity.dash.lensview");
38}39}
3940
41 // this is so we can access some protected members in scrollview
42class LensScrollView: public nux::ScrollView
43{
44public:
45 LensScrollView(NUX_FILE_LINE_DECL)
46 : nux::ScrollView(NUX_FILE_LINE_PARAM)
47 {
48
49 }
50
51 void ScrollToPosition(nux::Geometry & position)
52 {
53 // much of this code is copied from Nux/ScrollView.cpp
54 int child_y = position.y - GetGeometry ().y;
55 int child_y_diff = child_y - abs (_delta_y);
56
57 if (child_y_diff + position.height < GetGeometry ().height && child_y_diff >= 0)
58 {
59 return;
60 }
61
62 if (child_y_diff < 0)
63 {
64 ScrollUp (1, abs (child_y_diff));
65 }
66 else
67 {
68 int size = child_y_diff - GetGeometry ().height;
69
70 // always keeps the top of a view on the screen
71 size += position.height;
72
73 ScrollDown (1, size);
74 }
75 }
76
77};
78
79
40NUX_IMPLEMENT_OBJECT_TYPE(LensView);80NUX_IMPLEMENT_OBJECT_TYPE(LensView);
4181
42LensView::LensView()82LensView::LensView()
@@ -59,12 +99,37 @@
59 SetupResults();99 SetupResults();
60 SetupFilters();100 SetupFilters();
61101
62 PlacesStyle::GetDefault()->columns_changed.connect(sigc::mem_fun(this, &LensView::OnColumnsChanged));102 PlacesStyle::GetDefault()->columns_changed.connect(sigc::mem_fun(this, &LensView::OnColumnsChanged));
63103
64 lens_->connected.changed.connect([&](bool is_connected) { if (is_connected) initial_activation_ = true; });104 lens_->connected.changed.connect([&](bool is_connected) { if (is_connected) initial_activation_ = true; });
65 search_string.changed.connect([&](std::string const& search) { lens_->Search(search); });105 search_string.changed.connect([&](std::string const& search) { lens_->Search(search); });
66 filters_expanded.changed.connect([&](bool expanded) { fscroll_view_->SetVisible(expanded); QueueRelayout(); OnColumnsChanged(); });106 filters_expanded.changed.connect([&](bool expanded) { fscroll_view_->SetVisible(expanded); QueueRelayout(); OnColumnsChanged(); });
67 active.changed.connect(sigc::mem_fun(this, &LensView::OnActiveChanged));107 active.changed.connect(sigc::mem_fun(this, &LensView::OnActiveChanged));
108
109 ubus_.RegisterInterest(UBUS_RESULT_VIEW_KEYNAV_CHANGED, [this] (GVariant* data) {
110 // we get this signal when a result view keynav changes,
111 // its a bad way of doing this but nux ABI needs to be broken
112 // to do it properly
113 nux::Geometry focused_pos;
114 g_variant_get (data, "(iiii)", &focused_pos.x, &focused_pos.y, &focused_pos.width, &focused_pos.height);
115
116 for (auto it = categories_.begin(); it != categories_.end(); it++)
117 {
118 if ((*it)->GetLayout() != nullptr)
119 {
120 nux::View *child = (*it)->GetChildView();
121 if (child->HasKeyFocus())
122 {
123 focused_pos.x += child->GetGeometry().x;
124 focused_pos.y += child->GetGeometry().y - 30;
125 focused_pos.height += 30;
126 static_cast<LensScrollView *>(scroll_view_)->ScrollToPosition(focused_pos);
127 break;
128 }
129 }
130 }
131 });
132
68}133}
69134
70LensView::~LensView()135LensView::~LensView()
@@ -77,7 +142,7 @@
77{142{
78 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);143 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
79144
80 scroll_view_ = new nux::ScrollView(NUX_TRACKER_LOCATION);145 scroll_view_ = new LensScrollView(NUX_TRACKER_LOCATION);
81 scroll_view_->EnableVerticalScrollBar(true);146 scroll_view_->EnableVerticalScrollBar(true);
82 scroll_view_->EnableHorizontalScrollBar(false);147 scroll_view_->EnableHorizontalScrollBar(false);
83 layout_->AddView(scroll_view_);148 layout_->AddView(scroll_view_);
84149
=== modified file 'plugins/unityshell/src/LensView.h'
--- plugins/unityshell/src/LensView.h 2011-08-25 10:18:58 +0000
+++ plugins/unityshell/src/LensView.h 2011-09-27 14:22:23 +0000
@@ -51,7 +51,7 @@
51 virtual ~LensView();51 virtual ~LensView();
5252
53 Lens::Ptr lens() const;53 Lens::Ptr lens() const;
54 54
55 virtual void ActivateFirst();55 virtual void ActivateFirst();
5656
57 nux::Property<std::string> search_string;57 nux::Property<std::string> search_string;
@@ -82,7 +82,7 @@
82 virtual long ProcessEvent(nux::IEvent& ievent, long traverse_info, long event_info);82 virtual long ProcessEvent(nux::IEvent& ievent, long traverse_info, long event_info);
83 virtual void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);83 virtual void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);
84 virtual void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw);84 virtual void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw);
85 85
86 virtual bool AcceptKeyNavFocus();86 virtual bool AcceptKeyNavFocus();
87 virtual const gchar* GetName();87 virtual const gchar* GetName();
88 virtual void AddProperties(GVariantBuilder* builder);88 virtual void AddProperties(GVariantBuilder* builder);
@@ -102,6 +102,8 @@
102 FilterBar* filter_bar_;102 FilterBar* filter_bar_;
103103
104 guint fix_renderering_id_;104 guint fix_renderering_id_;
105
106 UBusManager ubus_;
105};107};
106108
107109
108110
=== modified file 'plugins/unityshell/src/ResultViewGrid.cpp'
--- plugins/unityshell/src/ResultViewGrid.cpp 2011-09-26 10:41:01 +0000
+++ plugins/unityshell/src/ResultViewGrid.cpp 2011-09-27 14:22:23 +0000
@@ -467,6 +467,13 @@
467 selected_index_ = std::max(0, selected_index_);467 selected_index_ = std::max(0, selected_index_);
468 selected_index_ = std::min(static_cast<int>(results_.size() - 1), selected_index_);468 selected_index_ = std::min(static_cast<int>(results_.size() - 1), selected_index_);
469 focused_uri_ = results_[selected_index_].uri;469 focused_uri_ = results_[selected_index_].uri;
470
471 int focused_x = (renderer_->width + horizontal_spacing) * (selected_index_ % items_per_row);
472 int focused_y = (renderer_->height + vertical_spacing) * (selected_index_ / items_per_row);
473
474 ubus_.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
475 g_variant_new("(iiii)", focused_x, focused_y, renderer_->width(), renderer_->height()));
476
470 NeedRedraw();477 NeedRedraw();
471}478}
472479
@@ -484,6 +491,13 @@
484 focused_uri_ = results_.front().uri;491 focused_uri_ = results_.front().uri;
485 selected_index_ = 0;492 selected_index_ = 0;
486 NeedRedraw();493 NeedRedraw();
494
495 int items_per_row = GetItemsPerRow();
496 int focused_x = (renderer_->width + horizontal_spacing) * (selected_index_ % items_per_row);
497 int focused_y = (renderer_->height + vertical_spacing) * (selected_index_ / items_per_row);
498
499 ubus_.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
500 g_variant_new("(iiii)", focused_x, focused_y, renderer_->width(), renderer_->height()));
487 }501 }
488 else502 else
489 {503 {
490504
=== modified file 'plugins/unityshell/src/UBusMessages.h'
--- plugins/unityshell/src/UBusMessages.h 2011-09-22 09:46:55 +0000
+++ plugins/unityshell/src/UBusMessages.h 2011-09-27 14:22:23 +0000
@@ -68,5 +68,7 @@
68#define UBUS_BACKGROUND_REQUEST_COLOUR_EMIT "REQUEST_BACKGROUND_COLOUR_EMIT"68#define UBUS_BACKGROUND_REQUEST_COLOUR_EMIT "REQUEST_BACKGROUND_COLOUR_EMIT"
6969
70#define UBUS_DASH_SIZE_CHANGED "DASH_SIZE_CHANGED"70#define UBUS_DASH_SIZE_CHANGED "DASH_SIZE_CHANGED"
71// FIXME - fix the nux focus api so we don't need this
72#define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED"
7173
72#endif // UBUS_MESSAGES_H74#endif // UBUS_MESSAGES_H