Merge lp:~3v1n0/unity/hints-on-first-run into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 3713
Proposed branch: lp:~3v1n0/unity/hints-on-first-run
Merge into: lp:unity
Diff against target: 225 lines (+101/-15)
6 files modified
panel/PanelMenuView.cpp (+22/-14)
plugins/unityshell/src/unityshell.cpp (+37/-0)
plugins/unityshell/src/unityshell.h (+2/-0)
shortcuts/ShortcutController.cpp (+5/-1)
shortcuts/ShortcutController.h (+2/-0)
tests/test_shortcut_controller.cpp (+33/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/hints-on-first-run
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Brandon Schaefer (community) Approve
Review via email: mp+210320@code.launchpad.net

Commit message

UnityScreen: show the shortcut hint on first run

Description of the change

As designed, we show the shortcut hints the first time an user run unity.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Nice :). LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'panel/PanelMenuView.cpp'
2--- panel/PanelMenuView.cpp 2014-03-06 09:26:03 +0000
3+++ panel/PanelMenuView.cpp 2014-03-12 22:56:47 +0000
4@@ -693,22 +693,30 @@
5 if (BAMF_IS_WINDOW(window))
6 {
7 BamfView *view = reinterpret_cast<BamfView*>(window);
8- std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList();
9 Window window_xid = bamf_window_get_xid(window);
10
11- if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end())
12+ if (bamf_window_get_window_type(window) == BAMF_WINDOW_DOCK)
13 {
14- /* If the active window is an unity window, we need to fallback to the
15- * top one, anyway we should always avoid to focus unity internal windows */
16- BamfWindow* top_win = GetBamfWindowForXid(GetTopWindow());
17-
18- if (top_win && top_win != window)
19- {
20- window = top_win;
21- }
22- else
23- {
24- return "";
25+ auto panel = const_cast<PanelMenuView*>(this)->GetTopLevelViewWindow();
26+ if (static_cast<nux::BaseWindow*>(panel)->GetInputWindowId() == window_xid)
27+ return desktop_name_;
28+
29+ std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList();
30+
31+ if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end())
32+ {
33+ /* If the active window is an unity window, we need to fallback to the
34+ * top one, anyway we should always avoid to focus unity internal windows */
35+ BamfWindow* top_win = GetBamfWindowForXid(GetTopWindow());
36+
37+ if (top_win && top_win != window)
38+ {
39+ window = top_win;
40+ }
41+ else
42+ {
43+ return "";
44+ }
45 }
46 }
47
48@@ -718,7 +726,7 @@
49 }
50 else if (!IsValidWindow(window_xid))
51 {
52- return "";
53+ return "";
54 }
55
56 if (WindowManager::Default().IsWindowMaximized(window_xid) && !use_appname)
57
58=== modified file 'plugins/unityshell/src/unityshell.cpp'
59--- plugins/unityshell/src/unityshell.cpp 2014-03-07 19:18:30 +0000
60+++ plugins/unityshell/src/unityshell.cpp 2014-03-12 22:56:47 +0000
61@@ -138,6 +138,7 @@
62 const int MAX_BUFFER_AGE = 11;
63 const int FRAMES_TO_REDRAW_ON_RESUME = 10;
64 const std::string RELAYOUT_TIMEOUT = "relayout-timeout";
65+const std::string FIRST_RUN_STAMP = "first_run.stamp";
66 } // namespace local
67 } // anon namespace
68
69@@ -3663,6 +3664,7 @@
70 auto shortcuts_modeller = std::make_shared<shortcut::CompizModeller>();
71 shortcut_controller_ = std::make_shared<shortcut::Controller>(base_window_raiser, shortcuts_modeller);
72 AddChild(shortcut_controller_.get());
73+ ShowFirstRunHints();
74
75 // Setup Session Controller
76 auto manager = std::make_shared<session::GnomeManager>();
77@@ -3742,6 +3744,41 @@
78 return menus_->KeyGrabber()->GetActions();
79 }
80
81+void UnityScreen::ShowFirstRunHints()
82+{
83+ sources_.AddTimeoutSeconds(1, [this] {
84+ auto const& cache_dir = glib::gchar_to_string(g_get_user_cache_dir())+"/unity/";
85+ if (!g_file_test((cache_dir+local::FIRST_RUN_STAMP).c_str(), G_FILE_TEST_EXISTS))
86+ {
87+ // We focus the panel, so the shortcut hint will be hidden at first user input
88+ auto const& panels = panel_controller_->panels();
89+ if (!panels.empty())
90+ {
91+ auto panel_win = static_cast<nux::BaseWindow*>(panels.front()->GetTopLevelViewWindow());
92+ SaveInputThenFocus(panel_win->GetInputWindowId());
93+ }
94+ shortcut_controller_->first_run = true;
95+ shortcut_controller_->Show();
96+
97+ if (g_mkdir_with_parents(cache_dir.c_str(), 0700) >= 0)
98+ {
99+ glib::Error error;
100+ g_file_set_contents((cache_dir+local::FIRST_RUN_STAMP).c_str(), "", 0, &error);
101+
102+ if (error)
103+ {
104+ LOG_ERROR(logger) << "Impossible to save the unity stamp file: " << error;
105+ }
106+ }
107+ else
108+ {
109+ LOG_ERROR(logger) << "Impossible to create unity cache folder!";
110+ }
111+ }
112+ return false;
113+ });
114+}
115+
116 /* Window init */
117
118 namespace
119
120=== modified file 'plugins/unityshell/src/unityshell.h'
121--- plugins/unityshell/src/unityshell.h 2014-03-07 03:37:43 +0000
122+++ plugins/unityshell/src/unityshell.h 2014-03-12 22:56:47 +0000
123@@ -306,6 +306,8 @@
124
125 void DamageBlurUpdateRegion(nux::Geometry const&);
126
127+ void ShowFirstRunHints();
128+
129 std::unique_ptr<na::TickSource> tick_source_;
130 std::unique_ptr<na::AnimationController> animation_controller_;
131
132
133=== modified file 'shortcuts/ShortcutController.cpp'
134--- shortcuts/ShortcutController.cpp 2013-11-20 21:39:40 +0000
135+++ shortcuts/ShortcutController.cpp 2014-03-12 22:56:47 +0000
136@@ -37,7 +37,8 @@
137
138 Controller::Controller(BaseWindowRaiser::Ptr const& base_window_raiser,
139 AbstractModeller::Ptr const& modeller)
140- : modeller_(modeller)
141+ : first_run(false)
142+ , modeller_(modeller)
143 , base_window_raiser_(base_window_raiser)
144 , visible_(false)
145 , enabled_(true)
146@@ -155,6 +156,7 @@
147 AddChild(view_.GetPointer());
148 view_->SetModel(modeller_->GetCurrentModel());
149 view_->background_color = WindowManager::Default().average_color();
150+ view_->closable = first_run();
151
152 if (!view_window_)
153 {
154@@ -197,6 +199,8 @@
155 if (view_window_ && view_window_->GetOpacity() > 0.0f)
156 {
157 view_->live_background = false;
158+ view_->closable = false;
159+ first_run = false;
160 animation::StartOrReverse(fade_animator_, animation::Direction::BACKWARD);
161 }
162 }
163
164=== modified file 'shortcuts/ShortcutController.h'
165--- shortcuts/ShortcutController.h 2013-11-14 00:17:19 +0000
166+++ shortcuts/ShortcutController.h 2014-03-12 22:56:47 +0000
167@@ -47,6 +47,8 @@
168 Controller(BaseWindowRaiser::Ptr const& raiser, AbstractModeller::Ptr const& modeller);
169 virtual ~Controller();
170
171+ nux::Property<bool> first_run;
172+
173 bool Show();
174 void Hide();
175
176
177=== modified file 'tests/test_shortcut_controller.cpp'
178--- tests/test_shortcut_controller.cpp 2013-09-25 00:48:03 +0000
179+++ tests/test_shortcut_controller.cpp 2014-03-12 22:56:47 +0000
180@@ -68,6 +68,7 @@
181 MOCK_METHOD1(SetOpacity, void(double));
182 using Controller::GetOffsetPerMonitor;
183 using Controller::ConstructView;
184+ using Controller::OnShowTimer;
185 using Controller::view_;
186
187 void RealSetOpacity(double value)
188@@ -188,5 +189,37 @@
189 color_property.changed.emit(nux::color::RandomColor());
190 }
191
192+TEST_F(TestShortcutController, FirstRunFalse)
193+{
194+ ASSERT_FALSE(controller_.first_run());
195+
196+ controller_.ConstructView();
197+ EXPECT_FALSE(controller_.view_->closable());
198+}
199+
200+TEST_F(TestShortcutController, FirstRunTrue)
201+{
202+ ASSERT_FALSE(controller_.first_run());
203+
204+ controller_.first_run = true;
205+ controller_.ConstructView();
206+ EXPECT_TRUE(controller_.view_->closable());
207+}
208+
209+TEST_F(TestShortcutController, UnsetFirstRunOnHide)
210+{
211+ controller_.first_run = true;
212+ controller_.ConstructView();
213+
214+ ASSERT_TRUE(controller_.view_->closable());
215+ controller_.Show();
216+ controller_.OnShowTimer();
217+ tick_source_.tick(100 * 1000);
218+ controller_.Hide();
219+
220+ EXPECT_FALSE(controller_.first_run());
221+ EXPECT_FALSE(controller_.view_->closable());
222+}
223+
224 }
225 }