Merge lp:~didrocks/unity/fix-lens-shortcuts into lp:unity

Proposed by Didier Roche-Tolomelli
Status: Merged
Approved by: Neil J. Patel
Approved revision: no longer in the source branch.
Merged at revision: 1520
Proposed branch: lp:~didrocks/unity/fix-lens-shortcuts
Merge into: lp:unity
Diff against target: 387 lines (+110/-33)
10 files modified
UnityCore/FilesystemLenses.cpp (+22/-6)
UnityCore/FilesystemLenses.h (+1/-0)
plugins/unityshell/src/DashController.cpp (+18/-0)
plugins/unityshell/src/DashController.h (+3/-0)
plugins/unityshell/src/DashView.cpp (+21/-0)
plugins/unityshell/src/DashView.h (+3/-0)
plugins/unityshell/src/Launcher.cpp (+15/-17)
plugins/unityshell/src/Launcher.h (+1/-1)
plugins/unityshell/src/unityshell.cpp (+23/-8)
plugins/unityshell/src/unityshell.h (+3/-1)
To merge this branch: bzr merge lp:~didrocks/unity/fix-lens-shortcuts
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+74468@code.launchpad.net

Description of the change

bring back lenses shortcut activation. Seems there is still an issue on
registering keybinding on first super invocation, but good enough for
main cases (LP: #834078).

No python code was written during this hacking period.

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

Awesome stuff! I found a couple of niggles, not sure if they are to do with your branch or not, so let me know:

- Pressing Super no longer shows the numbers on the icons :/
- If I press Super+f quickly, then the dash shows and hides, instead of just showing. I have to press super, wait around 100ms and then press f to make it show.

Any ideas?

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

The missing numbers and letters when holding down super is already in
Oneiric, so definitely not from this branch.

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

On 08/09/11 04:10, Didier Roche wrote:

+Lens::Ptr FilesystemLenses::Impl::GetLensForShortcut(std::string const&
lens_shortcut) const
+{
+ Lens::Ptr p;
+
+ for (Lens::Ptr lens: lenses_)
+ {
+ if (lens->shortcut == lens_shortcut)
+ {
+ p = lens;
+ break;
+ }
+ }
+
+ return p;
+}

In a previous branch I found some weirdness with break nor exiting the
new range based for loop. What I found fixed it was to return. So
something like this:

Lens::Ptr FilesystemLenses::Impl::GetLensForShortcut(std::string const&
lens_shortcut) const
{
   for (auto lens : lenses_)
   {
     if (lens->shortcut == lens_shortcut)
       return lens
   }
   return Lens::Ptr();
}

You could use "auto" or "Lens::Ptr const&". Using just Lens::Ptr causes
an extra object to be constructed and destroyed for each time through
the loop.

Tim

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

I've made the change mentionned by Tim in UnityCore, I've also fixed another one in UnityCore which had a similar pattern.

The "quick typing shortcut" is now fixed as well. But that makes me thing that we should have a keybinding controller which has a reference to both models to trigger the actions in both the Launcher and Dash, being able to know about both part and so avoiding the "show/hide" in a short period of time like we had there.
I initially put everything in the Launcher as it's where we controlled all the Super keys, but it's not the case anymore with this branch, so we should think about it. I'll get to it, but maybe after this release.

Please tell me if it fixes this :)
There is still the issue in first launch (will need to check compiz registration process with Sam)
The numbers not showing and acting is an oneiric regression, indeed, not related to this branch. I'll try to have a look there as well later (some people will apparently break some libunity ABI, and that + patch piloting + zomg new Qt! needs some attention from now ;))

Revision history for this message
Neil J. Patel (njpatel) wrote :

Sweet, approved!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/FilesystemLenses.cpp'
--- UnityCore/FilesystemLenses.cpp 2011-08-07 09:21:37 +0000
+++ UnityCore/FilesystemLenses.cpp 2011-09-08 06:47:28 +0000
@@ -114,6 +114,7 @@
114 LensList GetLenses() const;114 LensList GetLenses() const;
115 Lens::Ptr GetLens(std::string const& lens_id) const;115 Lens::Ptr GetLens(std::string const& lens_id) const;
116 Lens::Ptr GetLensAtIndex(std::size_t index) const;116 Lens::Ptr GetLensAtIndex(std::size_t index) const;
117 Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const;
117 std::size_t count() const;118 std::size_t count() const;
118119
119 void Init();120 void Init();
@@ -334,18 +335,15 @@
334335
335Lens::Ptr FilesystemLenses::Impl::GetLens(std::string const& lens_id) const336Lens::Ptr FilesystemLenses::Impl::GetLens(std::string const& lens_id) const
336{337{
337 Lens::Ptr p;338 for (auto lens: lenses_)
338
339 for (Lens::Ptr lens: lenses_)
340 {339 {
341 if (lens->id == lens_id)340 if (lens->id == lens_id)
342 {341 {
343 p = lens;342 return lens;
344 break;
345 }343 }
346 }344 }
347345
348 return p;346 return Lens::Ptr();
349}347}
350348
351Lens::Ptr FilesystemLenses::Impl::GetLensAtIndex(std::size_t index) const349Lens::Ptr FilesystemLenses::Impl::GetLensAtIndex(std::size_t index) const
@@ -361,6 +359,19 @@
361 return Lens::Ptr();359 return Lens::Ptr();
362}360}
363361
362Lens::Ptr FilesystemLenses::Impl::GetLensForShortcut(std::string const& lens_shortcut) const
363{
364 for (auto lens: lenses_)
365 {
366 if (lens->shortcut == lens_shortcut)
367 {
368 return lens;
369 }
370 }
371
372 return Lens::Ptr();
373}
374
364std::size_t FilesystemLenses::Impl::count() const375std::size_t FilesystemLenses::Impl::count() const
365{376{
366 return lenses_.size();377 return lenses_.size();
@@ -404,5 +415,10 @@
404 return pimpl->GetLensAtIndex(index);415 return pimpl->GetLensAtIndex(index);
405}416}
406417
418Lens::Ptr FilesystemLenses::GetLensForShortcut(std::string const& lens_shortcut) const
419{
420 return pimpl->GetLensForShortcut(lens_shortcut);
421}
422
407}423}
408}424}
409425
=== modified file 'UnityCore/FilesystemLenses.h'
--- UnityCore/FilesystemLenses.h 2011-07-27 17:35:31 +0000
+++ UnityCore/FilesystemLenses.h 2011-09-08 06:47:28 +0000
@@ -48,6 +48,7 @@
48 LensList GetLenses() const;48 LensList GetLenses() const;
49 Lens::Ptr GetLens(std::string const& lens_id) const;49 Lens::Ptr GetLens(std::string const& lens_id) const;
50 Lens::Ptr GetLensAtIndex(std::size_t index) const;50 Lens::Ptr GetLensAtIndex(std::size_t index) const;
51 Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const;
5152
52 sigc::signal<void> lenses_loaded;53 sigc::signal<void> lenses_loaded;
5354
5455
=== modified file 'plugins/unityshell/src/DashController.cpp'
--- plugins/unityshell/src/DashController.cpp 2011-09-08 04:49:34 +0000
+++ plugins/unityshell/src/DashController.cpp 2011-09-08 06:47:28 +0000
@@ -308,6 +308,24 @@
308 ShowDash();308 ShowDash();
309}309}
310310
311gboolean DashController::CheckShortcutActivation(const char* key_string)
312{
313 EnsureDash();
314 std::string lens_id = view_->GetIdForShortcutActivation(std::string(key_string));
315 if (lens_id != "")
316 {
317 OnActivateRequest(g_variant_new("(sus)", lens_id.c_str(), 0, ""));
318 return true;
319 }
320 return false;
321}
322
323std::vector<char> DashController::GetAllShortcuts()
324{
325 EnsureDash();
326 return view_->GetAllShortcuts();
327}
328
311// Introspectable329// Introspectable
312const gchar* DashController::GetName()330const gchar* DashController::GetName()
313{331{
314332
=== modified file 'plugins/unityshell/src/DashController.h'
--- plugins/unityshell/src/DashController.h 2011-09-08 04:49:34 +0000
+++ plugins/unityshell/src/DashController.h 2011-09-08 06:47:28 +0000
@@ -48,6 +48,9 @@
4848
49 nux::BaseWindow* window() const;49 nux::BaseWindow* window() const;
5050
51 gboolean CheckShortcutActivation(const char* key_string);
52 std::vector<char> GetAllShortcuts();
53
51 nux::Property<int> launcher_width;54 nux::Property<int> launcher_width;
52 nux::Property<int> panel_height;55 nux::Property<int> panel_height;
5356
5457
=== modified file 'plugins/unityshell/src/DashView.cpp'
--- plugins/unityshell/src/DashView.cpp 2011-09-08 03:04:04 +0000
+++ plugins/unityshell/src/DashView.cpp 2011-09-08 06:47:28 +0000
@@ -768,6 +768,27 @@
768 return false;768 return false;
769}769}
770770
771std::string const DashView::GetIdForShortcutActivation(std::string const& shortcut) const
772{
773 Lens::Ptr lens = lenses_.GetLensForShortcut(shortcut);
774 if (lens)
775 return lens->id;
776 return "";
777}
778
779std::vector<char> DashView::GetAllShortcuts()
780{
781 std::vector<char> result;
782
783 for (Lens::Ptr lens: lenses_.GetLenses())
784 {
785 std::string shortcut = lens->shortcut;
786 if(shortcut.size() > 0)
787 result.push_back(shortcut.at(0));
788 }
789 return result;
790}
791
771bool DashView::InspectKeyEvent(unsigned int eventType,792bool DashView::InspectKeyEvent(unsigned int eventType,
772 unsigned int key_sym,793 unsigned int key_sym,
773 const char* character)794 const char* character)
774795
=== modified file 'plugins/unityshell/src/DashView.h'
--- plugins/unityshell/src/DashView.h 2011-09-07 09:50:44 +0000
+++ plugins/unityshell/src/DashView.h 2011-09-08 06:47:28 +0000
@@ -56,6 +56,9 @@
56 void DisableBlur();56 void DisableBlur();
57 void OnActivateRequest(GVariant* args);57 void OnActivateRequest(GVariant* args);
5858
59 std::string const GetIdForShortcutActivation(std::string const& shortcut) const;
60 std::vector<char> GetAllShortcuts();
61
59 nux::View* default_focus() const;62 nux::View* default_focus() const;
6063
61private:64private:
6265
=== modified file 'plugins/unityshell/src/Launcher.cpp'
--- plugins/unityshell/src/Launcher.cpp 2011-09-08 04:49:34 +0000
+++ plugins/unityshell/src/Launcher.cpp 2011-09-08 06:47:28 +0000
@@ -235,7 +235,6 @@
235 _ignore_repeat_shortcut_handle = 0;235 _ignore_repeat_shortcut_handle = 0;
236236
237 _latest_shortcut = 0;237 _latest_shortcut = 0;
238 _super_pressed = false;
239 _shortcuts_shown = false;238 _shortcuts_shown = false;
240 _floating = false;239 _floating = false;
241 _hovered = false;240 _hovered = false;
@@ -1366,7 +1365,6 @@
13661365
1367void Launcher::StartKeyShowLauncher()1366void Launcher::StartKeyShowLauncher()
1368{1367{
1369 _super_pressed = true;
1370 _hide_machine->SetQuirk(LauncherHideMachine::LAST_ACTION_ACTIVATE, false);1368 _hide_machine->SetQuirk(LauncherHideMachine::LAST_ACTION_ACTIVATE, false);
13711369
1372 SetTimeStruct(&_times[TIME_TAP_SUPER]);1370 SetTimeStruct(&_times[TIME_TAP_SUPER]);
@@ -1391,7 +1389,6 @@
1391 clock_gettime(CLOCK_MONOTONIC, &current);1389 clock_gettime(CLOCK_MONOTONIC, &current);
13921390
1393 _hover_machine->SetQuirk(LauncherHoverMachine::SHORTCUT_KEYS_VISIBLE, false);1391 _hover_machine->SetQuirk(LauncherHoverMachine::SHORTCUT_KEYS_VISIBLE, false);
1394 _super_pressed = false;
1395 _shortcuts_shown = false;1392 _shortcuts_shown = false;
1396 QueueDraw();1393 QueueDraw();
13971394
@@ -2509,9 +2506,6 @@
2509 unsigned long key_state,2506 unsigned long key_state,
2510 char* key_string)2507 char* key_string)
2511{2508{
2512 if (!_super_pressed)
2513 return false;
2514
2515 LauncherModel::iterator it;2509 LauncherModel::iterator it;
25162510
2517 // Shortcut to start launcher icons. Only relies on Keycode, ignore modifier2511 // Shortcut to start launcher icons. Only relies on Keycode, ignore modifier
@@ -2520,16 +2514,6 @@
2520 if ((XKeysymToKeycode(x_display, (*it)->GetShortcut()) == key_code) ||2514 if ((XKeysymToKeycode(x_display, (*it)->GetShortcut()) == key_code) ||
2521 ((gchar)((*it)->GetShortcut()) == key_string[0]))2515 ((gchar)((*it)->GetShortcut()) == key_string[0]))
2522 {2516 {
2523 /*
2524 * start a timeout while repressing the same shortcut will be ignored.
2525 * This is because the keypress repeat is handled by Xorg and we have no
2526 * way to know if a press is an actual press or just an automated repetition
2527 * because the button is hold down. (key release events are sent in both cases)
2528 */
2529 if (_ignore_repeat_shortcut_handle > 0)
2530 g_source_remove(_ignore_repeat_shortcut_handle);
2531 _ignore_repeat_shortcut_handle = g_timeout_add(IGNORE_REPEAT_SHORTCUT_DURATION, &Launcher::ResetRepeatShorcutTimeout, this);
2532
2533 if (_latest_shortcut == (*it)->GetShortcut())2517 if (_latest_shortcut == (*it)->GetShortcut())
2534 return true;2518 return true;
25352519
@@ -2538,7 +2522,7 @@
2538 else2522 else
2539 (*it)->Activate(ActionArg(ActionArg::LAUNCHER, 0));2523 (*it)->Activate(ActionArg(ActionArg::LAUNCHER, 0));
25402524
2541 _latest_shortcut = (*it)->GetShortcut();2525 SetLatestShortcut((*it)->GetShortcut());
25422526
2543 // disable the "tap on super" check2527 // disable the "tap on super" check
2544 _times[TIME_TAP_SUPER].tv_sec = 0;2528 _times[TIME_TAP_SUPER].tv_sec = 0;
@@ -2550,6 +2534,20 @@
2550 return false;2534 return false;
2551}2535}
25522536
2537void Launcher::SetLatestShortcut(guint64 shortcut)
2538{
2539 _latest_shortcut = shortcut;
2540 /*
2541 * start a timeout while repressing the same shortcut will be ignored.
2542 * This is because the keypress repeat is handled by Xorg and we have no
2543 * way to know if a press is an actual press or just an automated repetition
2544 * because the button is hold down. (key release events are sent in both cases)
2545 */
2546 if (_ignore_repeat_shortcut_handle > 0)
2547 g_source_remove(_ignore_repeat_shortcut_handle);
2548 _ignore_repeat_shortcut_handle = g_timeout_add(IGNORE_REPEAT_SHORTCUT_DURATION, &Launcher::ResetRepeatShorcutTimeout, this);
2549}
2550
2553void2551void
2554Launcher::EdgeRevealTriggered(int mouse_x, int mouse_y)2552Launcher::EdgeRevealTriggered(int mouse_x, int mouse_y)
2555{2553{
25562554
=== modified file 'plugins/unityshell/src/Launcher.h'
--- plugins/unityshell/src/Launcher.h 2011-09-08 04:49:34 +0000
+++ plugins/unityshell/src/Launcher.h 2011-09-08 06:47:28 +0000
@@ -156,6 +156,7 @@
156 void EdgeRevealTriggered(int x, int y);156 void EdgeRevealTriggered(int x, int y);
157157
158 gboolean CheckSuperShortcutPressed(Display *x_display, unsigned int key_sym, unsigned long key_code, unsigned long key_state, char* key_string);158 gboolean CheckSuperShortcutPressed(Display *x_display, unsigned int key_sym, unsigned long key_code, unsigned long key_state, char* key_string);
159 void SetLatestShortcut(guint64 shortcut);
159160
160 nux::BaseWindow* GetParent()161 nux::BaseWindow* GetParent()
161 {162 {
@@ -397,7 +398,6 @@
397 bool _check_window_over_launcher;398 bool _check_window_over_launcher;
398399
399 bool _shortcuts_shown;400 bool _shortcuts_shown;
400 bool _super_pressed;
401 bool _keynav_activated;401 bool _keynav_activated;
402 guint64 _latest_shortcut;402 guint64 _latest_shortcut;
403403
404404
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2011-09-08 03:04:04 +0000
+++ plugins/unityshell/src/unityshell.cpp 2011-09-08 06:47:28 +0000
@@ -225,6 +225,7 @@
225 this);225 this);
226226
227 g_timeout_add(0, &UnityScreen::initPluginActions, this);227 g_timeout_add(0, &UnityScreen::initPluginActions, this);
228 super_keypressed_ = false;
228229
229 GeisAdapter::Default()->Run();230 GeisAdapter::Default()->Run();
230 gestureEngine = new GestureEngine(screen);231 gestureEngine = new GestureEngine(screen);
@@ -237,8 +238,6 @@
237 ubus_manager_.RegisterInterest(UBUS_PLACE_VIEW_SHOWN, [&](GVariant * args) { dash_is_open_ = true; });238 ubus_manager_.RegisterInterest(UBUS_PLACE_VIEW_SHOWN, [&](GVariant * args) { dash_is_open_ = true; });
238 ubus_manager_.RegisterInterest(UBUS_PLACE_VIEW_HIDDEN, [&](GVariant * args) { dash_is_open_ = false; });239 ubus_manager_.RegisterInterest(UBUS_PLACE_VIEW_HIDDEN, [&](GVariant * args) { dash_is_open_ = false; });
239240
240 EnsureKeybindings();
241
242 LOG_INFO(logger) << "UnityScreen constructed: " << timer.ElapsedSeconds() << "s";241 LOG_INFO(logger) << "UnityScreen constructed: " << timer.ElapsedSeconds() << "s";
243}242}
244243
@@ -301,7 +300,7 @@
301300
302}301}
303302
304void UnityScreen::EnsureKeybindings()303void UnityScreen::EnsureSuperKeybindings()
305{304{
306 for (auto action : _shortcut_actions)305 for (auto action : _shortcut_actions)
307 screen->removeAction(action.get());306 screen->removeAction(action.get());
@@ -313,19 +312,26 @@
313 guint64 shortcut = icon->GetShortcut();312 guint64 shortcut = icon->GetShortcut();
314 if (shortcut == 0)313 if (shortcut == 0)
315 continue;314 continue;
316315 CreateSuperNewAction(static_cast<char>(shortcut));
316 }
317
318 for (auto shortcut : dashController->GetAllShortcuts())
319 CreateSuperNewAction(shortcut);
320}
321
322void UnityScreen::CreateSuperNewAction(char shortcut)
323{
317 CompActionPtr action(new CompAction());324 CompActionPtr action(new CompAction());
318325
319 CompAction::KeyBinding binding;326 CompAction::KeyBinding binding;
320 std::ostringstream sout;327 std::ostringstream sout;
321 sout << "<Super>" << static_cast<char>(shortcut);328 sout << "<Super>" << shortcut;
322 binding.fromString(sout.str());329 binding.fromString(sout.str());
323330
324 action->setKey(binding);331 action->setKey(binding);
325332
326 screen->addAction(action.get());333 screen->addAction(action.get());
327 _shortcut_actions.push_back(action);334 _shortcut_actions.push_back(action);
328 }
329}335}
330336
331void UnityScreen::nuxPrologue()337void UnityScreen::nuxPrologue()
@@ -871,7 +877,14 @@
871 if ((result = XLookupString(&(event->xkey), key_string, 2, &key_sym, 0)) > 0)877 if ((result = XLookupString(&(event->xkey), key_string, 2, &key_sym, 0)) > 0)
872 {878 {
873 key_string[result] = 0;879 key_string[result] = 0;
874 skip_other_plugins = launcher->CheckSuperShortcutPressed(screen->dpy(), key_sym, event->xkey.keycode, event->xkey.state, key_string);880 if (super_keypressed_) {
881 skip_other_plugins = launcher->CheckSuperShortcutPressed(screen->dpy(), key_sym, event->xkey.keycode, event->xkey.state, key_string);
882 if (!skip_other_plugins) {
883 skip_other_plugins = dashController->CheckShortcutActivation(key_string);
884 if (skip_other_plugins)
885 launcher->SetLatestShortcut(key_string[0]);
886 }
887 }
875 }888 }
876 break;889 break;
877 }890 }
@@ -907,8 +920,9 @@
907 if (state & CompAction::StateInitKey)920 if (state & CompAction::StateInitKey)
908 action->setState(action->state() | CompAction::StateTermKey);921 action->setState(action->state() | CompAction::StateTermKey);
909922
923 super_keypressed_ = true;
910 launcher->StartKeyShowLauncher();924 launcher->StartKeyShowLauncher();
911 EnsureKeybindings ();925 EnsureSuperKeybindings ();
912 return false;926 return false;
913}927}
914928
@@ -916,6 +930,7 @@
916 CompAction::State state,930 CompAction::State state,
917 CompOption::Vector& options)931 CompOption::Vector& options)
918{932{
933 super_keypressed_ = false;
919 launcher->EndKeyShowLauncher();934 launcher->EndKeyShowLauncher();
920 return false;935 return false;
921}936}
922937
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2011-09-08 03:04:04 +0000
+++ plugins/unityshell/src/unityshell.h 2011-09-08 06:47:28 +0000
@@ -235,7 +235,8 @@
235235
236 void SendExecuteCommand();236 void SendExecuteCommand();
237237
238 void EnsureKeybindings ();238 void EnsureSuperKeybindings ();
239 void CreateSuperNewAction(char shortcut);
239240
240 static gboolean initPluginActions(gpointer data);241 static gboolean initPluginActions(gpointer data);
241 static void initLauncher(nux::NThread* thread, void* InitData);242 static void initLauncher(nux::NThread* thread, void* InitData);
@@ -281,6 +282,7 @@
281 typedef std::shared_ptr<CompAction> CompActionPtr;282 typedef std::shared_ptr<CompAction> CompActionPtr;
282 typedef std::vector<CompActionPtr> ShortcutActions;283 typedef std::vector<CompActionPtr> ShortcutActions;
283 ShortcutActions _shortcut_actions;284 ShortcutActions _shortcut_actions;
285 bool super_keypressed_;
284286
285 /* keyboard-nav mode */287 /* keyboard-nav mode */
286 CompWindow* newFocusedWindow;288 CompWindow* newFocusedWindow;