Merge lp:~azzar1/unity/shortcut-hint into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 1833
Proposed branch: lp:~azzar1/unity/shortcut-hint
Merge into: lp:unity
Diff against target: 2326 lines (+2055/-7)
25 files modified
plugins/unityshell/src/AbstractSeparator.cpp (+68/-0)
plugins/unityshell/src/AbstractSeparator.h (+49/-0)
plugins/unityshell/src/AbstractShortcutHint.h (+102/-0)
plugins/unityshell/src/BackgroundEffectHelper.cpp (+1/-1)
plugins/unityshell/src/LineSeparator.cpp (+73/-0)
plugins/unityshell/src/LineSeparator.h (+44/-0)
plugins/unityshell/src/MockShortcutHint.h (+72/-0)
plugins/unityshell/src/ShortcutController.cpp (+194/-0)
plugins/unityshell/src/ShortcutController.h (+87/-0)
plugins/unityshell/src/ShortcutHint.cpp (+137/-0)
plugins/unityshell/src/ShortcutHint.h (+53/-0)
plugins/unityshell/src/ShortcutHintPrivate.cpp (+79/-0)
plugins/unityshell/src/ShortcutHintPrivate.h (+39/-0)
plugins/unityshell/src/ShortcutModel.cpp (+60/-0)
plugins/unityshell/src/ShortcutModel.h (+64/-0)
plugins/unityshell/src/ShortcutView.cpp (+424/-0)
plugins/unityshell/src/ShortcutView.h (+93/-0)
plugins/unityshell/src/unityshell.cpp (+99/-1)
plugins/unityshell/src/unityshell.h (+9/-1)
plugins/unityshell/unityshell.xml.in (+6/-0)
standalone-clients/CMakeLists.txt (+26/-3)
standalone-clients/TestShortcut.cpp (+109/-0)
tests/CMakeLists.txt (+9/-1)
tests/test_shortcut_model.cpp (+84/-0)
tests/test_shortcut_private.cpp (+74/-0)
To merge this branch: bzr merge lp:~azzar1/unity/shortcut-hint
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
John Lea (community) design Approve
Tim Penhey (community) Approve
Review via email: mp+85575@code.launchpad.net

This proposal supersedes a proposal from 2011-12-07.

Description of the change

Display a shortcut hints overlay during the super key pressing.

It includes two unit tests and a standalone test.

Mockup: https://launchpadlibrarian.net/85352653/Super_key_shutcuts_overlay.png
Branch: http://ubuntuone.com/7cqBbWAbvXTRCT4ySFj7z4

Visual diff: http://ubuntuone.com/014zDKCoxaQYmtm8mS5pp8

Keep in mind that something is different because the shortcuts values are not hardcoded.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

I've just looked at few things but it seem good, however remember to unregister the ubus controller (i.e as done in lp:~vanvugt/unity/fix-887465-trunk ) in ~Controller and to use g_markup_escape_text ;).

Revision history for this message
Andrea Azzarone (azzar1) wrote : Posted in a previous version of this proposal

Marco you should not review a WIP :P

> I've just looked at few things but it seem good, however remember to unregister the ubus controller (i.e as done in lp:~vanvugt/unity/fix-887465-trunk )

Thanks for tip.

> and to use g_markup_escape_text ;).

We no longer need it ;)

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

That was not a review, just a comment! :)

Revision history for this message
Jeremy Bícha (jbicha) wrote : Posted in a previous version of this proposal

Hi, I hope you don't mind me giving feedback on the wording choices since it's still WIP...

Please use Trash instead of Rubbish Bin; the en_GB translation can change it back to Rubbish Bin.

The verb should consistently add the trailing "s" or not. In other words, "open" or "opens". For the Ubuntu system help, we left off the "s" but it could just as easily go the other way.

I'd like to see the keyboard keys always capitalized; I think some are stored as lowercase in metacity or whatever, but for display you should be able to upper-case them. ("Super + s" should be "Super + S").

How about "arrow keys" instead of "cursor keys"?

I believe menu bar is slightly preferred over top bar.

Revision history for this message
Andrea Azzarone (azzar1) wrote : Posted in a previous version of this proposal
Revision history for this message
Marco Biscaro (marcobiscaro2112) wrote : Posted in a previous version of this proposal

Another comment :) there is a typo here:

+ hints_.push_back(new shortcut::Hint(_("Switching"), "", "", _("Moves the foucs."), shortcut::HARDCODED_OPTION, _("Cursor Left & Right")));

Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

another comment, since this isn't yet a review :-)

properties should be lower case.

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

Hi Andy,

Can you add links for the design mockup, and a picture of what is
rendered with this branch?

Cheers,
Tim

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

Purely visual review:

The mockup lines are not white, but either transparent white or
transparent grey. The headings of each group are also not white.

The lines in the mockup are 1px thin grey with distinct ends. The view
has thicker lines that are brighter that taper at the ends.

The white-space above the "Windows" header is greater than the rest.

Some of the key-bindings are lower case, why is that?

Why are we missing some of the key bindings, like moving the focused
window to other workspaces?

Tim

review: Needs Information
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Purely visual review:
>
> The mockup lines are not white, but either transparent white or
> transparent grey. The headings of each group are also not white.
>
> The lines in the mockup are 1px thin grey with distinct ends. The view
> has thicker lines that are brighter that taper at the ends.
>

I'll look to it.

>
> The white-space above the "Windows" header is greater than the rest.
>

Yeah, because i've commented a couple of key bindings because they are not yet implemented.

>
> Some of the key-bindings are lower case, why is that?
>

Because Compiz CompOption gives me something like that: <Super>f... I've writed a very simple function to change it in "Super + f". I think the best solution is to capitalize each word of the shortcut.

> Why are we missing some of the key bindings, like moving the focused
> window to other workspaces?

As said, some options are not yet implmented. For example, regarding "Move focused window to different workspace" I can't find it in CCSM.

Revision history for this message
John Lea (johnlea) wrote :

Looking great! ;-) However there are a few minor issues that need to be fixed before this lands.

The feedback below is based on comparing the implementation screenshot posted with the following designs:
- https://launchpadlibrarian.net/85352653/Super_key_shutcuts_overlay.png (the design itself)
- https://launchpadlibrarian.net/86861725/keyboard_shortcuts_sizes.png (the grid the design is build on)

Items in need of fixing:

1. The divider lines should by 10% opacity (while remaining 100% white)

2. The divider should start flush with text, and end flush with grid (see grid design above)

3. The divider lines should have flat ends

4. The spacing of the title "Keyboard Shortcuts" is slightly out, should have slightly more space above than below (see design)

5. The spacing of the section titles is slightly out, should have slightly more space above each title than below (see design)

6. The shortcuts need updating to exactly match those specified in the following document https://docs.google.com/a/canonical.com/document/d/1jqeKtIJwqLtl58Wk_fqjr9Rrgxn9zsouCYOo-cZsLSE/edit?authkey=CLGG9NkJ&hl=en_GB

Once these are fixed we are good to go, thx!

review: Needs Fixing (design)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> > Why are we missing some of the key bindings, like moving the focused
> > window to other workspaces?
>
> As said, some options are not yet implmented. For example, regarding "Move
> focused window to different workspace" I can't find it in CCSM.

It's under desktop wall -> bindings -> Move with window within wall

Plus, I put here for reference as well, the bottom edge has some issues here:
 - http://ubuntuone.com/5bB2px39meddmAtL4bomM2

review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> 6. The shortcuts need updating to exactly match those specified in the
> following document https://docs.google.com/a/canonical.com/document/d
> /1jqeKtIJwqLtl58Wk_fqjr9Rrgxn9zsouCYOo-cZsLSE/edit?authkey=CLGG9NkJ&hl=en_GB

About the Alt+` shortcut... As it depends to the keyboard layout (i.e. in the Italian we have Alt+\ in fact), I guess that it should be localized...

Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Looking great! ;-) However there are a few minor issues that need to be fixed
> before this lands.
>
> The feedback below is based on comparing the implementation screenshot posted
> with the following designs:
> - https://launchpadlibrarian.net/85352653/Super_key_shutcuts_overlay.png (the
> design itself)
> - https://launchpadlibrarian.net/86861725/keyboard_shortcuts_sizes.png (the
> grid the design is build on)
>
> Items in need of fixing:
>
> 1. The divider lines should by 10% opacity (while remaining 100% white)
>

Done.

> 2. The divider should start flush with text, and end flush with grid (see grid
> design above)

Done.

>
> 3. The divider lines should have flat ends

Done.

>
> 4. The spacing of the title "Keyboard Shortcuts" is slightly out, should have
> slightly more space above than below (see design)
>

Done.

> 5. The spacing of the section titles is slightly out, should have slightly
> more space above each title than below (see design)

Done.

>
> 6. The shortcuts need updating to exactly match those specified in the
> following document https://docs.google.com/a/canonical.com/document/d
> /1jqeKtIJwqLtl58Wk_fqjr9Rrgxn9zsouCYOo-cZsLSE/edit?authkey=CLGG9NkJ&hl=en_GB
>
> Once these are fixed we are good to go, thx!

I'll do it tomorrow.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

Ok ready for the review. I've fixed something in the layout but I don't know if I've fixed the Marco's problem. Marco can you test it please? If you still have the same problem, can you check your DPI?

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

A general pass over the code and it seems OK, but nothing in UnityCore.

review: Approve
Revision history for this message
John Lea (johnlea) wrote :

awesome, everything perfect, great to see a attached .png with the visual design matched up against the implementation.

thanks!

review: Approve (design)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

I've just checked again this branch, but I still get that visual issue that I've already mentioned :(

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

I'm working on a branch dependent on this (lp:~3v1n0/unity/unity-dialog), working to fix the issue I got.

So, approving.

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

Attempt to merge into lp:unity failed due to conflicts:

text conflict in standalone-clients/CMakeLists.txt

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'plugins/unityshell/src/AbstractSeparator.cpp'
--- plugins/unityshell/src/AbstractSeparator.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/AbstractSeparator.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,68 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
17 *
18 */
19
20#include "AbstractSeparator.h"
21
22#include "Nux/Nux.h"
23
24namespace unity
25{
26
27AbstractSeparator::AbstractSeparator(NUX_FILE_LINE_DECL)
28 : nux::View(NUX_FILE_LINE_PARAM)
29 , color_(nux::color::White)
30 , alpha0_(0.0f)
31 , alpha1_(0.10f)
32 , border_size_(0)
33{
34}
35
36// Maybe it's better to use default arguments?
37AbstractSeparator::AbstractSeparator(nux::Color const& color, float alpha0,
38 float alpha1, int border, NUX_FILE_LINE_DECL)
39 : nux::View(NUX_FILE_LINE_PARAM)
40 , color_(color)
41 , alpha0_(alpha0)
42 , alpha1_(alpha1)
43 , border_size_(border)
44{
45}
46
47AbstractSeparator::~AbstractSeparator()
48{
49
50}
51
52void AbstractSeparator::SetColor(nux::Color const &color)
53{
54 color_ = color;
55}
56
57void AbstractSeparator::SetAlpha(float alpha0, float alpha1)
58{
59 alpha0_ = alpha0;
60 alpha1_ = alpha1;
61}
62
63void AbstractSeparator::SetBorderSize(int border)
64{
65 border_size_ = border;
66}
67
68} // namespace unity
069
=== added file 'plugins/unityshell/src/AbstractSeparator.h'
--- plugins/unityshell/src/AbstractSeparator.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/AbstractSeparator.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,49 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
17 *
18 */
19
20#ifndef UNITYSHELL_ABSTRACTSEPARATOR_H
21#define UNITYSHELL_ABSTRACTSEPARATOR_H
22
23#include <Nux/Nux.h>
24#include <Nux/View.h>
25
26namespace unity
27{
28
29class AbstractSeparator: public nux::View
30{
31public:
32 AbstractSeparator(NUX_FILE_LINE_PROTO);
33 AbstractSeparator(nux::Color const& color, float alpha0, float alpha1, int vorder, NUX_FILE_LINE_PROTO);
34 ~AbstractSeparator();
35
36 void SetColor(nux::Color const& color);
37 void SetAlpha(float alpha0, float alpha1);
38 void SetBorderSize(int border);
39
40protected:
41 nux::Color color_;
42 float alpha0_;
43 float alpha1_;
44 int border_size_;
45};
46
47} // namespace unity
48
49#endif // UNITYSHELL_ABSTRACTSEPARATOR_H
050
=== added file 'plugins/unityshell/src/AbstractShortcutHint.h'
--- plugins/unityshell/src/AbstractShortcutHint.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/AbstractShortcutHint.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,102 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#ifndef UNITYSHELL_ABSTRACT_SHORTCUT_ICON_H
21#define UNITYSHELL_ABSTRACT_SHORTCUT_ICON_H
22
23#include <string>
24
25#include <Nux/Nux.h>
26#include <NuxCore/Property.h>
27
28namespace unity
29{
30namespace shortcut
31{
32
33enum OptionType
34{
35 COMPIZ_KEY_OPTION = 0,
36 COMPIZ_MOUSE_OPTION,
37 HARDCODED_OPTION
38 /* GSETTINGS_OPTION,
39 * GCONF_OPTION */
40};
41
42class AbstractHint
43{
44public:
45 // Ctor
46 AbstractHint(std::string const& category,
47 std::string const& prefix,
48 std::string const& postfix,
49 std::string const& description,
50 OptionType const type,
51 std::string const& arg1,
52 std::string const& arg2 = "",
53 std::string const& arg3 = "")
54 : category(category)
55 , prefix(prefix)
56 , postfix(postfix)
57 , description(description)
58 , type(type)
59 , arg1(arg1)
60 , arg2(arg2)
61 , arg3(arg3)
62 {
63 }
64
65 // Copy ctor
66 AbstractHint(unity::shortcut::AbstractHint const& obj)
67 : category(obj.category())
68 , prefix(obj.prefix())
69 , postfix(obj.postfix())
70 , description(obj.description())
71 , type(obj.type())
72 , arg1(obj.arg1())
73 , arg2(obj.arg2())
74 , arg3(obj.arg3())
75 , value(obj.value())
76 , shortkey(obj.shortkey())
77 {
78 }
79
80 // Dtor
81 virtual ~AbstractHint(){};
82
83 // Public Methods
84 virtual bool Fill() = 0;
85
86 // Properties
87 nux::Property<std::string> category;
88 nux::Property<std::string> prefix;
89 nux::Property<std::string> postfix;
90 nux::Property<std::string> description;
91 nux::Property<OptionType> type;
92 nux::Property<std::string> arg1;
93 nux::Property<std::string> arg2;
94 nux::Property<std::string> arg3;
95 nux::Property<std::string> value;
96 nux::Property<std::string> shortkey;
97};
98
99} // namespace shortcut
100} // namespace unity
101
102#endif // UNITYSHELL_ABSTRACT_SHORTCUT_ICON_H
0103
=== modified file 'plugins/unityshell/src/BackgroundEffectHelper.cpp'
--- plugins/unityshell/src/BackgroundEffectHelper.cpp 2012-01-05 02:47:09 +0000
+++ plugins/unityshell/src/BackgroundEffectHelper.cpp 2012-01-13 15:39:27 +0000
@@ -72,7 +72,7 @@
72{72{
73 for (BackgroundEffectHelper * bg_effect_helper : registered_list_)73 for (BackgroundEffectHelper * bg_effect_helper : registered_list_)
74 {74 {
75 if (bg_effect_helper->cache_dirty || !bg_effect_helper->owner)75 if (bg_effect_helper->cache_dirty || !bg_effect_helper->owner || !bg_effect_helper->enabled)
76 continue;76 continue;
7777
78 if (!geo.Intersect (bg_effect_helper->blur_geometry_).IsNull())78 if (!geo.Intersect (bg_effect_helper->blur_geometry_).IsNull())
7979
=== added file 'plugins/unityshell/src/LineSeparator.cpp'
--- plugins/unityshell/src/LineSeparator.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/LineSeparator.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,73 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
17 *
18 */
19
20#include "LineSeparator.h"
21
22#include "Nux/Nux.h"
23
24namespace unity
25{
26
27HSeparator::HSeparator()
28{
29 SetMinimumHeight(1);
30 SetMaximumHeight(1);
31}
32
33HSeparator::HSeparator(nux::Color const& color, float alpha0, float alpha1, int border)
34 : AbstractSeparator(color, alpha0, alpha1, border)
35{
36 SetMinimumHeight(1);
37 SetMaximumHeight(1);
38}
39
40HSeparator::~HSeparator()
41{
42}
43
44void HSeparator::Draw(nux::GraphicsEngine &GfxContext, bool force_draw)
45{
46 nux::Geometry base = GetGeometry();
47 base.OffsetPosition(3, 0);
48 base.OffsetSize(-6, 0);
49 int y0 = base.y + base.GetHeight() / 2;
50
51 nux::GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetBlend(TRUE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
52
53 if (base.GetWidth() - 2 * border_size_ > 0)
54 {
55 nux::Color color0 = color_;
56 nux::Color color1 = color_;
57 color0.alpha = alpha0_;
58 color1.alpha = alpha1_;
59 nux::GetPainter().Draw2DLine(GfxContext, base.x, y0, base.x + border_size_, y0, color0, color1);
60 nux::GetPainter().Draw2DLine(GfxContext, base.x + border_size_, y0, base.x + base.GetWidth() - border_size_, y0, color1, color1);
61 nux::GetPainter().Draw2DLine(GfxContext, base.x + base.GetWidth() - border_size_, y0, base.x + base.GetWidth(), y0, color1, color0);
62 }
63 else
64 {
65 nux::Color color1 = color_;
66 color1.alpha = alpha1_;
67 nux::GetPainter().Draw2DLine(GfxContext, base.x, y0, base.x + base.GetWidth(), y0, color1, color1);
68 }
69
70 nux::GetGraphicsDisplay()->GetGraphicsEngine()->GetRenderStates().SetBlend(FALSE);
71}
72
73} // namespace unity
074
=== added file 'plugins/unityshell/src/LineSeparator.h'
--- plugins/unityshell/src/LineSeparator.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/LineSeparator.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,44 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
17 *
18 */
19
20#ifndef UNITYSHELL_HSEPARATOR_H
21#define UNITYSHELL_HSEPARATOR_H
22
23#include "AbstractSeparator.h"
24
25namespace unity
26{
27
28class HSeparator: public AbstractSeparator
29{
30public:
31 HSeparator();
32 HSeparator(nux::Color const& color, float alpha0, float alpha1, int border);
33
34 ~HSeparator();
35
36protected:
37 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
38 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {};
39
40};
41
42} // namespace unity
43
44#endif // UNITYSHELL_HSEPARATOR_H
045
=== added file 'plugins/unityshell/src/MockShortcutHint.h'
--- plugins/unityshell/src/MockShortcutHint.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/MockShortcutHint.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,72 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#ifndef UNITYSHELL_MOCK_SHORTCUT_HINT_H
21#define UNITYSHELL_MOCK_SHORTCUT_HINT_H
22
23#include "AbstractShortcutHint.h"
24
25namespace unity
26{
27namespace shortcut
28{
29
30class MockHint : public AbstractHint
31{
32public:
33 // Ctor and dtor
34 MockHint(std::string const& category,
35 std::string const& prefix,
36 std::string const& postfix,
37 std::string const& description,
38 OptionType const type,
39 std::string const& arg1,
40 std::string const& arg2 = "",
41 std::string const& arg3 = "")
42 : AbstractHint(category, prefix, postfix, description, type, arg1, arg2, arg3)
43 {
44 }
45
46 ~MockHint() {};
47
48 // Methods...
49 bool Fill()
50 {
51 switch (type())
52 {
53 case COMPIZ_MOUSE_OPTION:
54 case COMPIZ_KEY_OPTION:
55 value = arg1() + "-" + arg2();
56 shortkey = prefix() + value() + postfix();
57 return true;
58
59 case HARDCODED_OPTION:
60 value = arg1();
61 shortkey = prefix() + value() + postfix();
62 return true;
63 }
64
65 return false;
66 }
67};
68
69} // shortcut hint
70} // namespace unity
71
72#endif // UNITYSHELL_MOCK_SHORTCUT_HINT_H
073
=== added file 'plugins/unityshell/src/ShortcutController.cpp'
--- plugins/unityshell/src/ShortcutController.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutController.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,194 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
17 */
18
19#include "ShortcutController.h"
20
21#include "UBusMessages.h"
22#include "ubus-server.h"
23#include "WindowManager.h"
24
25namespace unity
26{
27namespace shortcut
28{
29namespace
30{
31const unsigned int SUPER_TAP_DURATION = 650;
32} // anonymouse namespace;
33
34Controller::Controller(std::list<AbstractHint*>& hints)
35 : view_window_(0)
36 , visible_(false)
37 , show_timer_(0)
38 , fade_in_animator_(new Animator(100))
39 , fade_out_animator_(new Animator(100))
40
41{
42 bg_color_ = nux::Color(0.0, 0.0, 0.0, 0.5);
43
44 UBusServer *ubus = ubus_server_get_default();
45 bg_update_handle_ = ubus_server_register_interest(ubus, UBUS_BACKGROUND_COLOR_CHANGED,
46 (UBusCallback)&Controller::OnBackgroundUpdate,
47 this);
48
49 model_.reset(new Model(hints));
50
51 model_->Fill();
52 ConstructView();
53
54 fade_in_animator_->animation_updated.connect(sigc::mem_fun(this, &Controller::OnFadeInUpdated));
55 fade_in_animator_->animation_ended.connect(sigc::mem_fun(this, &Controller::OnFadeInEnded));
56 fade_out_animator_->animation_updated.connect(sigc::mem_fun(this, &Controller::OnFadeOutUpdated));
57 fade_out_animator_->animation_ended.connect(sigc::mem_fun(this, &Controller::OnFadeOutEnded));
58}
59
60Controller::~Controller()
61{
62 ubus_server_unregister_interest(ubus_server_get_default(), bg_update_handle_);
63
64 if (fade_in_animator_)
65 delete fade_in_animator_;
66
67 if (fade_out_animator_)
68 delete fade_out_animator_;
69
70 if (view_window_)
71 view_window_->UnReference();
72
73 view_.Release();
74}
75
76
77void Controller::OnFadeInUpdated(double opacity)
78{
79 view_window_->SetOpacity(opacity);
80}
81
82void Controller::OnFadeInEnded()
83{
84 view_window_->SetOpacity(1.0);
85}
86
87void Controller::OnFadeOutUpdated(double progress)
88{
89 double opacity = CLAMP(1.0f - progress, 0.0f, 1.0f);
90 view_window_->SetOpacity(opacity);
91}
92
93void Controller::OnFadeOutEnded()
94{
95 view_window_->SetOpacity(0.0);
96}
97
98
99void Controller::OnBackgroundUpdate(GVariant* data, Controller* self)
100{
101 gdouble red, green, blue, alpha;
102 g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha);
103 self->bg_color_ = nux::Color(red, green, blue, alpha);
104
105 if (self->view_)
106 self->view_->background_color = self->bg_color_;
107}
108
109void Controller::Show()
110{
111 if (show_timer_)
112 g_source_remove (show_timer_);
113 show_timer_ = g_timeout_add(SUPER_TAP_DURATION, &Controller::OnShowTimer, this);
114
115 model_->Fill();
116 visible_ = true;
117}
118
119gboolean Controller::OnShowTimer(gpointer data)
120{
121 Controller* self = static_cast<Controller*>(data);
122
123 ubus_server_send_message(ubus_server_get_default(),
124 UBUS_PLACE_VIEW_CLOSE_REQUEST,
125 NULL);
126
127 if (self->visible_)
128 {
129 self->view_->SetupBackground(true);
130 self->fade_out_animator_->Stop();
131 self->fade_in_animator_->Start(self->view_window_->GetOpacity());
132 }
133
134 self->show_timer_ = 0;
135 return FALSE;
136}
137
138void Controller::ConstructView()
139{
140 view_ = View::Ptr(new View());
141 view_->SetModel(model_);
142 view_->background_color = bg_color_;
143
144 if (!view_window_)
145 {
146 main_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
147 main_layout_->SetVerticalExternalMargin(0);
148 main_layout_->SetHorizontalExternalMargin(0);
149
150 view_window_ = new nux::BaseWindow("ShortcutHint");
151 view_window_->SinkReference();
152 view_window_->SetLayout(main_layout_);
153 view_window_->SetBackgroundColor(nux::Color(0x00000000));
154 }
155
156 main_layout_->AddView(view_.GetPointer(), 1);
157
158 view_->SetupBackground(false);
159 view_window_->SetOpacity(0.0);
160 view_window_->ShowWindow(true);
161}
162
163void Controller::SetWorkspace(nux::Geometry const& geo)
164{
165 workarea_ = geo;
166 view_window_->SetGeometry(workarea_);
167}
168
169void Controller::Hide()
170{
171 if (!visible_)
172 return;
173
174 visible_ = false;
175
176 if (view_window_)
177 {
178 view_->SetupBackground(false);
179 fade_in_animator_->Stop();
180 fade_out_animator_->Start(1.0 - view_window_->GetOpacity());
181 }
182
183 if (show_timer_)
184 g_source_remove(show_timer_);
185 show_timer_ = 0;
186}
187
188bool Controller::Visible()
189{
190 return visible_;
191}
192
193} // namespace shortcut
194} // namespace unity
0195
=== added file 'plugins/unityshell/src/ShortcutController.h'
--- plugins/unityshell/src/ShortcutController.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutController.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
17 */
18
19#ifndef UNITYSHELL_SHORTCUTCONTROLLER_H
20#define UNITYSHELL_SHORTCUTCONTROLLER_H
21
22#include <boost/shared_ptr.hpp>
23
24#include <Nux/Nux.h>
25#include <Nux/BaseWindow.h>
26#include <Nux/HLayout.h>
27#include <NuxCore/Color.h>
28
29#include "Animator.h"
30#include "ShortcutModel.h"
31#include "ShortcutView.h"
32
33namespace unity
34{
35namespace shortcut
36{
37
38class Controller
39{
40public:
41 typedef std::shared_ptr<Controller> Ptr;
42
43 // Ctor and dtor
44 Controller(std::list<AbstractHint*>& hints);
45 ~Controller();
46
47 // Public Methods
48 void Show();
49 void Hide();
50
51 bool Visible();
52
53 void SetWorkspace(nux::Geometry const& geo);
54
55private:
56 // Private Methods
57 void ConstructView();
58 static void OnBackgroundUpdate(GVariant* data, Controller* self);
59 void OnFadeInUpdated(double opacity);
60 void OnFadeInEnded();
61 void OnFadeOutUpdated(double opacity);
62 void OnFadeOutEnded();
63
64 static gboolean OnShowTimer(gpointer data);
65
66 // Private Members
67 View::Ptr view_;
68 Model::Ptr model_;
69
70 nux::Geometry workarea_;
71 nux::BaseWindow* view_window_;
72 nux::HLayout* main_layout_;
73
74 bool visible_;
75 nux::Color bg_color_;
76 guint show_timer_;
77 guint bg_update_handle_;
78
79 Animator* fade_in_animator_;
80 Animator* fade_out_animator_;
81};
82
83} // namespace shortcut
84} // namespace unity
85
86#endif //UNITYSHELL_SHORTCUTHINTCONTROLLER_H
87
088
=== added file 'plugins/unityshell/src/ShortcutHint.cpp'
--- plugins/unityshell/src/ShortcutHint.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutHint.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,137 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#include "ShortcutHint.h"
21
22#include <core/core.h> // Compiz...
23#include <NuxCore/Logger.h>
24
25#include "ShortcutHintPrivate.h"
26
27namespace unity
28{
29namespace shortcut
30{
31namespace
32{
33 nux::logging::Logger logger("unity.shortcut");
34} // anonymouse namespace
35
36// Ctor
37Hint::Hint(std::string const& category,
38 std::string const& prefix,
39 std::string const& postfix,
40 std::string const& description,
41 OptionType const type,
42 std::string const& arg1,
43 std::string const& arg2,
44 std::string const& arg3)
45 : AbstractHint(category, prefix, postfix, description, type, arg1, arg2, arg3)
46{
47}
48
49// Dtor
50Hint::~Hint()
51{
52}
53
54/*
55 * Gets and fills the shortcut value.
56 * Returns true if everything was OK, returns false otherwise.
57 * Use member property Value to get it.
58 */
59bool Hint::Fill()
60{
61 switch(type())
62 {
63 case COMPIZ_MOUSE_OPTION:
64 {
65 // Arg1 = Plugin name
66 // Arg2 = key Option name
67 CompPlugin* p = CompPlugin::find(arg1().c_str());
68
69 if (!p)
70 return false;
71
72 foreach (CompOption &opt, p->vTable->getOptions())
73 {
74 if (opt.name() == arg2())
75 {
76 std::string temp = impl::FixMouseShortcut(impl::FixShortcutFormat(opt.value().action().buttonToString()));
77 temp = impl::ProperCase(temp);
78
79 if (value() != temp)
80 {
81 value = temp;
82 shortkey = prefix() + value() + postfix();
83 }
84
85 return true;
86 }
87 }
88
89 break;
90 }
91 break;
92
93 case COMPIZ_KEY_OPTION:
94 {
95 // Arg1 = Plugin name
96 // Arg2 = key Option name
97 CompPlugin* p = CompPlugin::find(arg1().c_str());
98
99 if (!p)
100 return false;
101
102 foreach (CompOption &opt, p->vTable->getOptions())
103 {
104 if (opt.name() == arg2())
105 {
106 std::string temp = impl::FixShortcutFormat(opt.value().action().keyToString());
107 temp = impl::ProperCase(temp);
108
109 if (value() != temp)
110 {
111 value = temp;
112 shortkey = prefix() + value() + postfix();
113 }
114
115 return true;
116 }
117 }
118
119 break;
120 }
121 case HARDCODED_OPTION:
122 if (value != arg1())
123 {
124 value = arg1();
125 shortkey = prefix() + value() + postfix();
126 }
127 return true;
128
129 default:
130 LOG_WARNING(logger) << "Unable to find the option type" << type();
131 }
132
133 return false;
134}
135
136} // namespace shortcut
137} // namespace unity
0138
=== added file 'plugins/unityshell/src/ShortcutHint.h'
--- plugins/unityshell/src/ShortcutHint.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutHint.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,53 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#ifndef UNITYSHELL_SHORTCUTHINT_H
21#define UNITYSHELL_SHORTCUTHINT_H
22
23#include "AbstractShortcutHint.h"
24
25namespace unity
26{
27namespace shortcut
28{
29
30class Hint : public AbstractHint
31{
32public:
33 // Ctor
34 Hint(std::string const& category,
35 std::string const& prefix,
36 std::string const& postfix,
37 std::string const& description,
38 OptionType const type,
39 std::string const& arg1,
40 std::string const& arg2 = "",
41 std::string const& arg3 = "");
42
43 // Dtor
44 ~Hint();
45
46 // Public methods
47 bool Fill();
48};
49
50} // namespace shortcut
51} // namespace unity
52
53 #endif // UNITYSHELL_SHORTCUTHINT_H
054
=== added file 'plugins/unityshell/src/ShortcutHintPrivate.cpp'
--- plugins/unityshell/src/ShortcutHintPrivate.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutHintPrivate.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,79 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
17 */
18
19#include "ShortcutHintPrivate.h"
20
21#include <boost/algorithm/string/replace.hpp>
22
23namespace unity
24{
25namespace shortcut
26{
27namespace impl
28{
29
30std::string FixShortcutFormat(std::string const& scut)
31{
32 std::string ret(scut.begin(), scut.end() - 1);
33
34 boost::replace_all(ret, "<", "");
35 boost::replace_all(ret, ">", " + ");
36
37 if (scut[scut.size()-1] != '>')
38 ret += scut[scut.size()-1];
39
40 return ret;
41}
42
43std::string FixMouseShortcut(std::string const& scut)
44{
45 std::string ret(scut);
46
47 boost::replace_all(ret, "Button1", "Left Mouse");
48 boost::replace_all(ret, "Button2", "Middle Mouse");
49 boost::replace_all(ret, "Button3", "Right Mouse");
50
51 return ret;
52}
53
54std::string ProperCase(std::string const& str)
55{
56 std::string ret = str;
57
58 bool cap_next = true;
59
60 for (unsigned int i = 0; i < ret.length(); ++i)
61 {
62 if (cap_next and isalpha(ret[i]))
63 {
64 ret[i]=toupper(ret[i]);
65 cap_next = false;
66 }
67 else
68 {
69 cap_next = ispunct(ret[i]) || isspace(ret[i]);
70 }
71 }
72
73 return ret;
74}
75
76} // namespace impl
77} // namespace shortcut
78} // namespace unity
79
080
=== added file 'plugins/unityshell/src/ShortcutHintPrivate.h'
--- plugins/unityshell/src/ShortcutHintPrivate.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutHintPrivate.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
17 */
18
19#ifndef UNITYSHELL_SHORTCUT_HINT_PRIVATE_H
20#define UNITYSHELL_SHORTCUT_HINT_PRIVATE_H
21
22#include <string>
23
24namespace unity
25{
26namespace shortcut
27{
28namespace impl
29{
30
31std::string FixShortcutFormat(std::string const& scut);
32std::string FixMouseShortcut(std::string const& scut);
33std::string ProperCase(std::string const& str);
34
35} // namespace impl
36} // namespace shortcut
37} // namespace unity
38
39#endif // UNITYSHELL_SHORTCUT_HINT_PRIVATE_H
040
=== added file 'plugins/unityshell/src/ShortcutModel.cpp'
--- plugins/unityshell/src/ShortcutModel.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutModel.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,60 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#include "ShortcutModel.h"
21
22namespace unity
23{
24namespace shortcut
25{
26
27// Ctor
28Model::Model(std::list<AbstractHint*>& hints)
29{
30 for (auto hint : hints)
31 AddHint(hint);
32}
33
34// Dtor
35Model::~Model()
36{
37}
38
39
40void Model::AddHint(AbstractHint* hint)
41{
42 if (!hint)
43 return;
44
45 if (hints_.find(hint->category()) == hints_.end())
46 categories_.push_back(hint->category());
47
48 hints_[hint->category()].push_back(hint);
49}
50
51
52void Model::Fill()
53{
54 for (auto category : categories_)
55 for (auto item : hints_[category])
56 item->Fill();
57}
58
59} // namespace shortcut
60} // namespace unity
061
=== added file 'plugins/unityshell/src/ShortcutModel.h'
--- plugins/unityshell/src/ShortcutModel.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutModel.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,64 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#ifndef UNITYSHELL_SHORTCUSMODEL_H
21#define UNITYSHELL_SHORTCUSMODEL_H
22
23#include <boost/noncopyable.hpp>
24#include <map>
25#include <memory>
26#include <list>
27#include <string>
28#include <vector>
29
30#include "AbstractShortcutHint.h"
31
32namespace unity
33{
34namespace shortcut
35{
36
37class Model : boost::noncopyable
38{
39public:
40 typedef std::shared_ptr<Model> Ptr;
41
42 // Ctor and dtor
43 Model(std::list<AbstractHint*>& hints);
44 ~Model();
45
46 // Accessors
47 std::vector<std::string>& categories() { return categories_; }
48 std::map<std::string, std::list<AbstractHint*>>& hints() { return hints_; }
49
50 void Fill();
51
52private:
53 // Private functions
54 void AddHint(AbstractHint* hint);
55
56 // Private members
57 std::vector<std::string> categories_;
58 std::map<std::string, std::list<AbstractHint*>> hints_;
59};
60
61} // shortcut
62} // unity
63
64#endif // UNITYSHELL_SHORTCUTS_H
065
=== added file 'plugins/unityshell/src/ShortcutView.cpp'
--- plugins/unityshell/src/ShortcutView.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutView.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,424 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
17 * Jay Taoko <jay.taoko@canonical.com>
18 */
19
20#include "ShortcutView.h"
21
22#include <glib/gi18n-lib.h>
23#include <boost/algorithm/string.hpp>
24#include <UnityCore/GLibWrapper.h>
25
26#include "LineSeparator.h"
27#include "StaticCairoText.h"
28
29namespace unity
30{
31namespace shortcut
32{
33namespace
34{
35 int SECTION_NAME_FONT_SIZE = 17/1.33;
36 int SHORTKEY_ENTRY_FONT_SIZE = 13/1.33;
37 int INTER_SPACE_SHORTKEY_DESCRIPTION = 10;
38 int SHORTKEY_COLUMN_WIDTH = 150;
39 int DESCRIPTION_COLUMN_WIDTH = 265;
40 int LINE_SPACING = 5;
41} // namespace anonymouse
42
43NUX_IMPLEMENT_OBJECT_TYPE(View);
44
45View::View(NUX_FILE_LINE_DECL)
46 : nux::View(NUX_FILE_LINE_PARAM)
47{
48 layout_ = new nux::VLayout();
49 layout_->SetPadding(50, 38);
50 layout_->SetSpaceBetweenChildren(20);
51 SetLayout(layout_);
52
53 background_top_ = nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_top.png", -1, true);
54 background_left_ = nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_left.png", -1, true);
55 background_corner_ = nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_corner.png", -1, true);
56 rounding_texture_ = nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_round_rect.png", -1, true);
57
58 std::string header = "<b>";
59 header += _("Keyboard Shortcuts");
60 header += "</b>";
61
62 nux::StaticText* header_view = new nux::StaticText(header.c_str(), NUX_TRACKER_LOCATION);
63 header_view->SetTextPointSize(20/1.33);
64 header_view->SetFontName("Ubuntu");
65 layout_->AddView(header_view, 1 , nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
66
67 layout_->AddView(new HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
68
69 columns_layout_ = new nux::HLayout();
70 columns_layout_->SetSpaceBetweenChildren(30);
71 layout_->AddLayout(columns_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
72
73 // Column 1...
74 columns_.push_back(new nux::VLayout());
75 columns_layout_->AddLayout(columns_[0], 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
76
77 // Column 2...
78 columns_.push_back(new nux::VLayout());
79 columns_layout_->AddLayout(columns_[1], 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
80
81 bg_effect_helper_.owner = this;
82}
83
84View::~View()
85{
86 if (background_top_ != NULL)
87 background_top_->UnReference();
88
89 if (background_left_ != NULL)
90 background_left_->UnReference();
91
92 if (background_corner_ != NULL)
93 background_corner_->UnReference();
94
95 if (rounding_texture_ != NULL)
96 rounding_texture_->UnReference();
97}
98
99void View::SetModel(Model::Ptr model)
100{
101 model_ = model;
102
103 // Fills the columns...
104 RenderColumns();
105}
106
107Model::Ptr View::GetModel()
108{
109 return model_;
110}
111
112void View::SetupBackground(bool enabled)
113{
114 bg_effect_helper_.enabled = enabled;
115}
116
117nux::LinearLayout* View::CreateSectionLayout(const char* section_name)
118{
119 nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);
120
121 std::string name = "<b>";
122 name += std::string(section_name);
123 name += "</b>";
124
125
126 nux::StaticText* section_name_view = new nux::StaticText(name.c_str(), NUX_TRACKER_LOCATION);
127 section_name_view->SetTextPointSize(SECTION_NAME_FONT_SIZE);
128 section_name_view->SetFontName("Ubuntu");
129 layout->AddView(new nux::SpaceLayout(10, 10, 10, 10), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
130 layout->AddView(section_name_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
131 layout->AddView(new nux::SpaceLayout(15, 15, 15, 15), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
132
133 return layout;
134}
135
136nux::LinearLayout* View::CreateShortKeyEntryLayout(AbstractHint* hint)
137{
138 nux::HLayout* layout = new nux::HLayout("EntryLayout", NUX_TRACKER_LOCATION);
139 nux::HLayout* shortkey_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
140 nux::HLayout* description_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
141
142 glib::String shortkey(g_markup_escape_text(hint->shortkey().c_str(), -1));
143
144 std::string skey = "<b>";
145 skey += shortkey.Str();
146 skey += "</b>";
147
148 nux::StaticText* shortkey_view = new nux::StaticText(skey, NUX_TRACKER_LOCATION);
149 shortkey_view->SetTextAlignment(nux::StaticText::ALIGN_LEFT);
150 shortkey_view->SetFontName("Ubuntu");
151 shortkey_view->SetTextPointSize(SHORTKEY_ENTRY_FONT_SIZE);
152 shortkey_view->SetMinimumWidth(SHORTKEY_COLUMN_WIDTH);
153 shortkey_view->SetMaximumWidth(SHORTKEY_COLUMN_WIDTH);
154
155 glib::String es_desc(g_markup_escape_text(hint->description().c_str(), -1));
156
157 nux::StaticText* description_view = new nux::StaticText(es_desc.Value(), NUX_TRACKER_LOCATION);
158 description_view->SetTextAlignment(nux::StaticText::ALIGN_LEFT);
159 shortkey_view->SetFontName("Ubuntu");
160 description_view->SetTextPointSize(SHORTKEY_ENTRY_FONT_SIZE);
161 description_view->SetMinimumWidth(DESCRIPTION_COLUMN_WIDTH);
162 description_view->SetMaximumWidth(DESCRIPTION_COLUMN_WIDTH);
163
164 shortkey_layout->AddView(shortkey_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
165 shortkey_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
166 shortkey_layout->SetMinimumWidth(SHORTKEY_COLUMN_WIDTH);
167 shortkey_layout->SetMaximumWidth(SHORTKEY_COLUMN_WIDTH);
168
169 description_layout->AddView(description_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
170 description_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
171 description_layout->SetMinimumWidth(DESCRIPTION_COLUMN_WIDTH);
172 description_layout->SetMaximumWidth(DESCRIPTION_COLUMN_WIDTH);
173
174 layout->AddLayout(shortkey_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
175 layout->AddLayout(description_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
176 layout->SetSpaceBetweenChildren(INTER_SPACE_SHORTKEY_DESCRIPTION);
177 description_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
178
179 auto on_shortkey_changed = [](std::string const& new_shortkey, nux::StaticText* view) {
180 std::string skey = "<b>";
181 skey += new_shortkey;
182 skey += "</b>";
183
184 view->SetText(skey);
185 };
186
187 hint->shortkey.changed.connect(sigc::bind(sigc::slot<void, std::string const&, nux::StaticText*>(on_shortkey_changed), shortkey_view));
188
189 return layout;
190}
191
192nux::LinearLayout* View::CreateIntermediateLayout()
193{
194 nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);
195 layout->SetSpaceBetweenChildren(LINE_SPACING);
196
197 return layout;
198}
199
200void View::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
201{
202 return;
203}
204
205void View::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
206{
207 nux::Geometry base = GetGeometry();
208 GfxContext.PushClippingRectangle(base);
209
210 // clear region
211 gPainter.PaintBackground(GfxContext, base);
212
213 nux::Geometry background_geo;
214
215 background_geo.width = base.width;
216 background_geo.height = base.height;
217 background_geo.x = (base.width - background_geo.width)/2;
218 background_geo.y = (base.height - background_geo.height)/2;
219
220 // magic constant comes from texture contents (distance to cleared area)
221 const int internal_offset = 20;
222 nux::Geometry internal_clip(background_geo.x + internal_offset,
223 background_geo.y + internal_offset,
224 background_geo.width - internal_offset * 2,
225 background_geo.height - internal_offset * 2);
226 GfxContext.PushClippingRectangle(internal_clip);
227
228 nux::Geometry geo_absolute = GetAbsoluteGeometry();
229 if (BackgroundEffectHelper::blur_type != BLUR_NONE)
230 {
231 nux::Geometry blur_geo(geo_absolute.x, geo_absolute.y, base.width, base.height);
232 auto blur_texture = bg_effect_helper_.GetBlurRegion(blur_geo);
233
234 if (blur_texture.IsValid())
235 {
236 nux::TexCoordXForm texxform_blur_bg;
237 texxform_blur_bg.flip_v_coord = true;
238 texxform_blur_bg.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
239 texxform_blur_bg.uoffset = ((float) base.x) / geo_absolute.width;
240 texxform_blur_bg.voffset = ((float) base.y) / geo_absolute.height;
241
242 nux::ROPConfig rop;
243 rop.Blend = false;
244 rop.SrcBlend = GL_ONE;
245 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
246
247 gPainter.PushDrawTextureLayer(GfxContext, base,
248 blur_texture,
249 texxform_blur_bg,
250 nux::color::White,
251 true,
252 rop);
253 }
254 }
255
256 nux::ROPConfig rop;
257 rop.Blend = true;
258 rop.SrcBlend = GL_ONE;
259 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
260 gPainter.PushDrawColorLayer(GfxContext, internal_clip, background_color, false, rop);
261
262 // Make round corners
263 rop.Blend = true;
264 rop.SrcBlend = GL_ZERO;
265 rop.DstBlend = GL_SRC_ALPHA;
266 gPainter.PaintShapeCornerROP(GfxContext,
267 internal_clip,
268 nux::color::White,
269 nux::eSHAPE_CORNER_ROUND4,
270 nux::eCornerTopLeft | nux::eCornerTopRight |
271 nux::eCornerBottomLeft | nux::eCornerBottomRight,
272 true,
273 rop);
274
275 GfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
276
277 GfxContext.PopClippingRectangle();
278 GfxContext.PopClippingRectangle();
279
280 DrawBackground(GfxContext, background_geo);
281
282
283 layout_->ProcessDraw(GfxContext, force_draw);
284}
285
286
287void View::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)
288{
289 int border = 30;
290
291 GfxContext.GetRenderStates().SetBlend(TRUE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
292
293 nux::TexCoordXForm texxform;
294 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
295 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
296
297 // Draw TOP-LEFT CORNER
298 texxform.u0 = 0;
299 texxform.v0 = 0;
300 texxform.u1 = border;
301 texxform.v1 = border;
302 GfxContext.QRP_1Tex(geo.x, geo.y,
303 border, border, background_corner_->GetDeviceTexture(), texxform, nux::color::White);
304
305 // Draw TOP-RIGHT CORNER
306 texxform.u0 = 0;
307 texxform.v0 = 0;
308 texxform.u1 = border;
309 texxform.v1 = border;
310 texxform.flip_u_coord = true;
311 texxform.flip_v_coord = false;
312 GfxContext.QRP_1Tex(geo.x + geo.width - border, geo.y,
313 border, border, background_corner_->GetDeviceTexture(), texxform, nux::color::White);
314
315 // Draw BOTTOM-LEFT CORNER
316 texxform.u0 = 0;
317 texxform.v0 = 0;
318 texxform.u1 = border;
319 texxform.v1 = border;
320 texxform.flip_u_coord = false;
321 texxform.flip_v_coord = true;
322 GfxContext.QRP_1Tex(geo.x, geo.y + geo.height - border,
323 border, border, background_corner_->GetDeviceTexture(), texxform, nux::color::White);
324
325 // Draw BOTTOM-RIGHT CORNER
326 texxform.u0 = 0;
327 texxform.v0 = 0;
328 texxform.u1 = border;
329 texxform.v1 = border;
330 texxform.flip_u_coord = true;
331 texxform.flip_v_coord = true;
332 GfxContext.QRP_1Tex(geo.x + geo.width - border, geo.y + geo.height - border,
333 border, border, background_corner_->GetDeviceTexture(), texxform, nux::color::White);
334
335 int top_width = background_top_->GetWidth();
336 int top_height = background_top_->GetHeight();
337
338 // Draw TOP BORDER
339 texxform.u0 = 0;
340 texxform.v0 = 0;
341 texxform.u1 = top_width;
342 texxform.v1 = top_height;
343 texxform.flip_u_coord = false;
344 texxform.flip_v_coord = false;
345 GfxContext.QRP_1Tex(geo.x + border, geo.y, geo.width - border - border, border, background_top_->GetDeviceTexture(), texxform, nux::color::White);
346
347 // Draw BOTTOM BORDER
348 texxform.u0 = 0;
349 texxform.v0 = 0;
350 texxform.u1 = top_width;
351 texxform.v1 = top_height;
352 texxform.flip_u_coord = false;
353 texxform.flip_v_coord = true;
354 GfxContext.QRP_1Tex(geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, background_top_->GetDeviceTexture(), texxform, nux::color::White);
355
356
357 int left_width = background_left_->GetWidth();
358 int left_height = background_left_->GetHeight();
359
360 // Draw LEFT BORDER
361 texxform.u0 = 0;
362 texxform.v0 = 0;
363 texxform.u1 = left_width;
364 texxform.v1 = left_height;
365 texxform.flip_u_coord = false;
366 texxform.flip_v_coord = false;
367 GfxContext.QRP_1Tex(geo.x, geo.y + border, border, geo.height - border - border, background_left_->GetDeviceTexture(), texxform, nux::color::White);
368
369 // Draw RIGHT BORDER
370 texxform.u0 = 0;
371 texxform.v0 = 0;
372 texxform.u1 = left_width;
373 texxform.v1 = left_height;
374 texxform.flip_u_coord = true;
375 texxform.flip_v_coord = false;
376 GfxContext.QRP_1Tex(geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, background_left_->GetDeviceTexture(), texxform, nux::color::White);
377
378 GfxContext.GetRenderStates().SetBlend(FALSE);
379}
380
381void View::RenderColumns()
382{
383 int i = 0;
384 int column = 0;
385
386 for (auto category : model_->categories())
387 {
388 // Three sections in the fist column...
389 if (i > 2)
390 column = 1;
391
392 nux::LinearLayout* section_layout = CreateSectionLayout(category.c_str());
393 nux::LinearLayout* intermediate_layout = CreateIntermediateLayout();
394 intermediate_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
395
396 for (auto hint : model_->hints()[category])
397 {
398 //std::string str_value = hint->prefix() + hint->value() + hint->postfix();
399 //boost::replace_all(str_value, "&", "&amp;");
400 //boost::replace_all(str_value, "<", "&lt;");
401 //boost::replace_all(str_value, ">", "&gt;");
402
403 intermediate_layout->AddLayout(CreateShortKeyEntryLayout(hint), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);
404 }
405
406 section_layout->AddLayout(intermediate_layout, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
407
408 if (i == 0 or i==1 or i==3 or i==4)
409 {
410 // Add space before the line
411 section_layout->AddView(new nux::SpaceLayout(23, 23, 23, 23), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
412 section_layout->AddView(new HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
413 // Add space after the line
414 section_layout->AddView(new nux::SpaceLayout(20, 20, 20, 20), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
415 }
416
417 columns_[column]->AddView(section_layout, 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);
418
419 i++;
420 }
421}
422
423} // namespace shortcut
424} // namespace unity
0425
=== added file 'plugins/unityshell/src/ShortcutView.h'
--- plugins/unityshell/src/ShortcutView.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/ShortcutView.h 2012-01-13 15:39:27 +0000
@@ -0,0 +1,93 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
17 */
18
19#ifndef UNITYSHELL_SHORTCUTVIEW_H
20#define UNITYSHELL_SHORTCUTVIEW_H
21
22#include <Nux/Nux.h>
23#include <Nux/GridHLayout.h>
24#include <Nux/HLayout.h>
25#include <NuxCore/ObjectPtr.h>
26#include <NuxCore/Property.h>
27#include <Nux/StaticText.h>
28#include <Nux/View.h>
29#include <Nux/VLayout.h>
30
31#include "BackgroundEffectHelper.h"
32#include "ShortcutModel.h"
33
34namespace unity
35{
36namespace shortcut
37{
38
39class View : public nux::View
40{
41 NUX_DECLARE_OBJECT_TYPE(View, nux::View);
42public:
43 typedef nux::ObjectPtr<View> Ptr;
44
45 // Ctor and dtor
46 View(NUX_FILE_LINE_PROTO);
47 ~View();
48
49 // Public methods
50 void SetModel(Model::Ptr model);
51 Model::Ptr GetModel();
52
53 void SetupBackground(bool enabled);
54
55 // Properties
56 nux::Property<nux::Color> background_color;
57
58protected:
59 // Protected methods
60 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
61 void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
62
63private:
64 // Private methods
65 nux::LinearLayout* CreateSectionLayout(const char* section_name);
66 nux::LinearLayout* CreateShortKeyEntryLayout(AbstractHint* hint);
67 nux::LinearLayout* CreateIntermediateLayout();
68
69 void DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo);
70 void RenderColumns();
71
72 // Private members
73 Model::Ptr model_;
74
75 nux::BaseTexture* background_top_;
76 nux::BaseTexture* background_left_;
77 nux::BaseTexture* background_corner_;
78 nux::BaseTexture* rounding_texture_;
79
80 nux::VLayout* layout_;
81 nux::HLayout* columns_layout_;
82 std::vector<nux::VLayout*> columns_;
83
84 BackgroundEffectHelper bg_effect_helper_;
85
86};
87
88} // namespace shortcut
89
90} // namespace unity
91
92#endif // UNITYSHELL_SHORTCUTVIEW_H
93
094
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2012-01-09 16:49:50 +0000
+++ plugins/unityshell/src/unityshell.cpp 2012-01-13 15:39:27 +0000
@@ -97,6 +97,7 @@
97 , screen(screen)97 , screen(screen)
98 , cScreen(CompositeScreen::get(screen))98 , cScreen(CompositeScreen::get(screen))
99 , gScreen(GLScreen::get(screen))99 , gScreen(GLScreen::get(screen))
100 , enable_shortcut_overlay_(true)
100 , gestureEngine(nullptr)101 , gestureEngine(nullptr)
101 , wt(nullptr)102 , wt(nullptr)
102 , panelWindow(nullptr)103 , panelWindow(nullptr)
@@ -258,7 +259,8 @@
258 optionSetIconSizeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));259 optionSetIconSizeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
259 optionSetAutohideAnimationNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));260 optionSetAutohideAnimationNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
260 optionSetDashBlurExperimentalNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));261 optionSetDashBlurExperimentalNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
261 optionSetDevicesOptionNotify(boost::bind (&UnityScreen::optionChanged, this, _1, _2));262 optionSetDevicesOptionNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
263 optionSetShortcutOverlayNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
262 optionSetShowDesktopIconNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));264 optionSetShowDesktopIconNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
263 optionSetShowLauncherInitiate(boost::bind(&UnityScreen::showLauncherKeyInitiate, this, _1, _2, _3));265 optionSetShowLauncherInitiate(boost::bind(&UnityScreen::showLauncherKeyInitiate, this, _1, _2, _3));
264 optionSetShowLauncherTerminate(boost::bind(&UnityScreen::showLauncherKeyTerminate, this, _1, _2, _3));266 optionSetShowLauncherTerminate(boost::bind(&UnityScreen::showLauncherKeyTerminate, this, _1, _2, _3));
@@ -1120,6 +1122,7 @@
1120 // thing that could possibly make sense here.1122 // thing that could possibly make sense here.
1121 key_string[result] = 0;1123 key_string[result] = 0;
1122 if (super_keypressed_) {1124 if (super_keypressed_) {
1125 shortcut_controller_->Hide();
1123 skip_other_plugins = launcher.CheckSuperShortcutPressed(screen->dpy(), key_sym, event->xkey.keycode, event->xkey.state, key_string);1126 skip_other_plugins = launcher.CheckSuperShortcutPressed(screen->dpy(), key_sym, event->xkey.keycode, event->xkey.state, key_string);
1124 if (!skip_other_plugins) {1127 if (!skip_other_plugins) {
1125 skip_other_plugins = dash_controller_->CheckShortcutActivation(key_string);1128 skip_other_plugins = dash_controller_->CheckShortcutActivation(key_string);
@@ -1234,6 +1237,33 @@
1234 super_keypressed_ = true;1237 super_keypressed_ = true;
1235 launcher_controller_->launcher().StartKeyShowLauncher();1238 launcher_controller_->launcher().StartKeyShowLauncher();
1236 EnsureSuperKeybindings ();1239 EnsureSuperKeybindings ();
1240
1241 if (enable_shortcut_overlay_ and !shortcut_controller_->Visible())
1242 {
1243 static nux::Geometry last_geo;
1244 UScreen* uscreen = UScreen::GetDefault();
1245 int primary_monitor = uscreen->GetPrimaryMonitor();
1246 auto monitor_geo = uscreen->GetMonitorGeometry(primary_monitor);
1247
1248 int width = 970;
1249 int height = 680;
1250 int launcher_width = optionGetIconSize() + 18;
1251 int panel_height = 24;
1252 int x = monitor_geo.x + launcher_width + (monitor_geo.width - launcher_width- width) / 2;
1253 int y = monitor_geo.y + panel_height + (monitor_geo.height - panel_height - height) / 2;
1254
1255 nux::Geometry geo (x, y, width, height);
1256
1257 if (last_geo != geo)
1258 {
1259 shortcut_controller_->SetWorkspace(geo);
1260 last_geo = geo;
1261 }
1262
1263 if (last_geo.x > monitor_geo.x and last_geo.y > monitor_geo.y)
1264 shortcut_controller_->Show();
1265 }
1266
1237 return false;1267 return false;
1238}1268}
12391269
@@ -1243,6 +1273,7 @@
1243{1273{
1244 super_keypressed_ = false;1274 super_keypressed_ = false;
1245 launcher_controller_->launcher().EndKeyShowLauncher();1275 launcher_controller_->launcher().EndKeyShowLauncher();
1276 shortcut_controller_->Hide();
1246 return false;1277 return false;
1247}1278}
12481279
@@ -2176,6 +2207,9 @@
2176 screen->enterShowDesktopModeSetEnabled (this, optionGetShowMinimizedWindows ());2207 screen->enterShowDesktopModeSetEnabled (this, optionGetShowMinimizedWindows ());
2177 screen->leaveShowDesktopModeSetEnabled (this, optionGetShowMinimizedWindows ());2208 screen->leaveShowDesktopModeSetEnabled (this, optionGetShowMinimizedWindows ());
2178 break;2209 break;
2210 case UnityshellOptions::ShortcutOverlay:
2211 enable_shortcut_overlay_ = optionGetShortcutOverlay();
2212 break;
2179 case UnityshellOptions::ShowDesktopIcon:2213 case UnityshellOptions::ShowDesktopIcon:
2180 launcher_controller_->SetShowDesktopIcon(optionGetShowDesktopIcon());2214 launcher_controller_->SetShowDesktopIcon(optionGetShowDesktopIcon());
2181 break;2215 break;
@@ -2304,6 +2338,10 @@
2304 /* Setup Places */2338 /* Setup Places */
2305 dash_controller_.reset(new dash::Controller());2339 dash_controller_.reset(new dash::Controller());
2306 dash_controller_->on_realize.connect(sigc::mem_fun(this, &UnityScreen::OnDashRealized));2340 dash_controller_->on_realize.connect(sigc::mem_fun(this, &UnityScreen::OnDashRealized));
2341
2342 // Setup Shortcut Hint
2343 InitHints();
2344 shortcut_controller_.reset(new shortcut::Controller(hints_));
23072345
2308 AddChild(dash_controller_.get());2346 AddChild(dash_controller_.get());
23092347
@@ -2316,6 +2354,66 @@
2316 OnLauncherHiddenChanged();2354 OnLauncherHiddenChanged();
2317}2355}
23182356
2357void UnityScreen::InitHints()
2358{
2359 // TODO move category text into a vector...
2360
2361 // Launcher...
2362 std::string const launcher = _("Launcher");
2363
2364 hints_.push_back(new shortcut::Hint(launcher, "", _(" (Press)"), _("Open Launcher, displays shortcuts."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher" ));
2365 hints_.push_back(new shortcut::Hint(launcher, "", "", _("Open Launcher keyboard navigation mode."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "keyboard_focus"));
2366 hints_.push_back(new shortcut::Hint(launcher, "", "", _("Switch applications via Launcher."), shortcut::HARDCODED_OPTION, "Super + Tab"));
2367 hints_.push_back(new shortcut::Hint(launcher, "", _(" + 1 to 9"), _("Same as clicking on a Launcher icon."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2368 hints_.push_back(new shortcut::Hint(launcher, "", _(" + Shift + 1 to 9"), _("Open new window of the app."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2369 hints_.push_back(new shortcut::Hint(launcher, "", " + T", _("Open the Rubbish Bin."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2370
2371 // Dash...
2372 std::string const dash = _("Dash");
2373
2374 hints_.push_back(new shortcut::Hint(dash, "", _(" (Tap)"), _("Open the Dash Home."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2375 hints_.push_back(new shortcut::Hint(dash, "", " + A", _("Open the Dash App Lens."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2376 hints_.push_back(new shortcut::Hint(dash, "", " + F", _("Open the Dash Files Lens."), shortcut::COMPIZ_KEY_OPTION,"unityshell", "show_launcher"));
2377 hints_.push_back(new shortcut::Hint(dash, "", " + M", _("Open the Dash Music Lens."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2378 hints_.push_back(new shortcut::Hint(dash, "", "", _("Switches between Lenses."), shortcut::HARDCODED_OPTION, "Ctrl + Tab"));
2379 hints_.push_back(new shortcut::Hint(dash, "", "", _("Moves the focus."), shortcut::HARDCODED_OPTION, _("Cursor Keys")));
2380 hints_.push_back(new shortcut::Hint(dash, "", "", _("Open currently focused item."), shortcut::HARDCODED_OPTION, _("Enter & Return")));
2381 hints_.push_back(new shortcut::Hint(dash, "", "", _("'Run Command' mode."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "execute_command"));
2382
2383 // Top Bar
2384 std::string const topbar = _("Top Bar");
2385
2386 hints_.push_back(new shortcut::Hint(topbar, "", "", _("Reveals application menu."), shortcut::HARDCODED_OPTION, "Alt"));
2387 hints_.push_back(new shortcut::Hint(topbar, "", "", _("Opens the indicator menu."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "panel_first_menu"));
2388 hints_.push_back(new shortcut::Hint(topbar, "", "", _("Moves focus between indicators."), shortcut::HARDCODED_OPTION, _("Cursor Left or Right")));
2389
2390 // Switching
2391 std::string const switching = _("Switching");
2392
2393 hints_.push_back(new shortcut::Hint(switching, "", "", _("Switch between applications."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_forward"));
2394 hints_.push_back(new shortcut::Hint(switching, "", "", _("Switch windows of current application."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_next_window"));
2395 hints_.push_back(new shortcut::Hint(switching, "", "", _("Moves the focus."), shortcut::HARDCODED_OPTION, _("Cursor Left or Right")));
2396
2397 // Workspaces
2398 std::string const workspaces = _("Workspaces");
2399 hints_.push_back(new shortcut::Hint(workspaces, "", "", _("Spread workspaces."), shortcut::COMPIZ_KEY_OPTION, "expo", "expo_key"));
2400 hints_.push_back(new shortcut::Hint(workspaces, "", "", _("Switch workspaces."), shortcut::HARDCODED_OPTION, _("Super + Cursor Keys")));
2401 hints_.push_back(new shortcut::Hint(workspaces, "", " or Right", _("Move focused window to different workspace."), shortcut::HARDCODED_OPTION, _("Super + Alt + Cursor Keys")));
2402
2403 // Windows
2404 std::string const windows = _("Windows");
2405 hints_.push_back(new shortcut::Hint(windows, "", "", _("Spreads all windows in the current workspace."), shortcut::COMPIZ_KEY_OPTION, "scale", "initiate_all_key"));
2406 hints_.push_back(new shortcut::Hint(windows, "", "", _("Minimises all windows."), shortcut::COMPIZ_KEY_OPTION, "core", "show_desktop_key"));
2407 hints_.push_back(new shortcut::Hint(windows, "", "", _("Maximises the current window."), shortcut::COMPIZ_KEY_OPTION, "core", "maximize_window_key"));
2408 hints_.push_back(new shortcut::Hint(windows, "", "", _("Restores or minimises current window."), shortcut::COMPIZ_KEY_OPTION, "core", "unmaximize_window_key"));
2409 hints_.push_back(new shortcut::Hint(windows, "", " or Right", _("Semi-maximises current window."), shortcut::COMPIZ_KEY_OPTION, "grid", "put_left_key"));
2410 hints_.push_back(new shortcut::Hint(windows, "", "", _("Closes current window."), shortcut::COMPIZ_KEY_OPTION, "core", "close_window_key"));
2411 hints_.push_back(new shortcut::Hint(windows, "", "", _("Opens window accessibility menu."), shortcut::HARDCODED_OPTION, "Alt + Space"));
2412 hints_.push_back(new shortcut::Hint(windows, "", "", _("Places window in corresponding positions."), shortcut::HARDCODED_OPTION, "Ctrl + Alt + Num"));
2413 hints_.push_back(new shortcut::Hint(windows, "", " Drag", _("Move window."), shortcut::COMPIZ_MOUSE_OPTION, "move", "initiate_button"));
2414 hints_.push_back(new shortcut::Hint(windows, "", " Drag", _("Resize window."), shortcut::COMPIZ_MOUSE_OPTION, "resize", "initiate_button"));
2415}
2416
2319/* Window init */2417/* Window init */
2320UnityWindow::UnityWindow(CompWindow* window)2418UnityWindow::UnityWindow(CompWindow* window)
2321 : BaseSwitchWindow (dynamic_cast<BaseSwitchScreen *> (UnityScreen::get (screen)), window)2419 : BaseSwitchWindow (dynamic_cast<BaseSwitchScreen *> (UnityScreen::get (screen)), window)
23222420
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2012-01-06 04:53:09 +0000
+++ plugins/unityshell/src/unityshell.h 2012-01-13 15:39:27 +0000
@@ -39,6 +39,8 @@
39#include "DashSettings.h"39#include "DashSettings.h"
40#include "DashStyle.h"40#include "DashStyle.h"
41#include "FontSettings.h"41#include "FontSettings.h"
42#include "ShortcutController.h"
43#include "ShortcutHint.h"
42#include "LauncherController.h"44#include "LauncherController.h"
43#include "PanelController.h"45#include "PanelController.h"
44#include "PanelStyle.h"46#include "PanelStyle.h"
@@ -242,6 +244,8 @@
242 static void OnQuicklistEndKeyNav(GVariant* data, void* value);244 static void OnQuicklistEndKeyNav(GVariant* data, void* value);
243 static void OnLauncherStartKeyNav(GVariant* data, void* value);245 static void OnLauncherStartKeyNav(GVariant* data, void* value);
244 static void OnLauncherEndKeyNav(GVariant* data, void* value);246 static void OnLauncherEndKeyNav(GVariant* data, void* value);
247
248 void InitHints();
245249
246 dash::Settings dash_settings_;250 dash::Settings dash_settings_;
247 dash::Style dash_style_;251 dash::Style dash_style_;
@@ -253,6 +257,10 @@
253 panel::Controller::Ptr panel_controller_;257 panel::Controller::Ptr panel_controller_;
254 switcher::Controller::Ptr switcher_controller_;258 switcher::Controller::Ptr switcher_controller_;
255259
260 shortcut::Controller::Ptr shortcut_controller_;
261 std::list<shortcut::AbstractHint*> hints_;
262 bool enable_shortcut_overlay_;
263
256 GestureEngine* gestureEngine;264 GestureEngine* gestureEngine;
257 nux::WindowThread* wt;265 nux::WindowThread* wt;
258 nux::BaseWindow* panelWindow;266 nux::BaseWindow* panelWindow;
@@ -266,7 +274,7 @@
266 guint32 _redraw_handle;274 guint32 _redraw_handle;
267 gint _edge_pointerY;275 gint _edge_pointerY;
268 guint _ubus_handles[3];276 guint _ubus_handles[3];
269277
270 typedef std::shared_ptr<CompAction> CompActionPtr;278 typedef std::shared_ptr<CompAction> CompActionPtr;
271 typedef std::vector<CompActionPtr> ShortcutActions;279 typedef std::vector<CompActionPtr> ShortcutActions;
272 ShortcutActions _shortcut_actions;280 ShortcutActions _shortcut_actions;
273281
=== modified file 'plugins/unityshell/unityshell.xml.in'
--- plugins/unityshell/unityshell.xml.in 2011-12-08 21:16:50 +0000
+++ plugins/unityshell/unityshell.xml.in 2012-01-13 15:39:27 +0000
@@ -341,6 +341,12 @@
341 <_name>Always</_name>341 <_name>Always</_name>
342 </desc>342 </desc>
343 </option>343 </option>
344
345 <option name="shortcut_overlay" type="bool">
346 <_short>Enable Shortcut Hints Overlay</_short>
347 <_long>Enable Shortcut Hints Overlay</_long>
348 <default>true</default>
349 </option>
344350
345 <option name="show_desktop_icon" type="bool">351 <option name="show_desktop_icon" type="bool">
346 <_short>Show "Desktop Icon" in the launcher</_short>352 <_short>Show "Desktop Icon" in the launcher</_short>
347353
=== modified file 'standalone-clients/CMakeLists.txt'
--- standalone-clients/CMakeLists.txt 2012-01-06 13:10:01 +0000
+++ standalone-clients/CMakeLists.txt 2012-01-13 15:39:27 +0000
@@ -452,8 +452,32 @@
452 )452 )
453add_dependencies (bg-hash unity-core-${UNITY_API_VERSION})453add_dependencies (bg-hash unity-core-${UNITY_API_VERSION})
454454
455add_executable (test-shortcut
456 TestShortcut.cpp
457 ${UNITY_SRC}/AbstractSeparator.cpp
458 ${UNITY_SRC}/AbstractSeparator.h
459 ${UNITY_SRC}/AbstractShortcutHint.h
460 ${UNITY_SRC}/Animator.cpp
461 ${UNITY_SRC}/Animator.h
462 ${UNITY_SRC}/BackgroundEffectHelper.cpp
463 ${UNITY_SRC}/BackgroundEffectHelper.h
464 ${UNITY_SRC}/LineSeparator.cpp
465 ${UNITY_SRC}/LineSeparator.h
466 ${UNITY_SRC}/MockShortcutHint.h
467 ${UNITY_SRC}/ShortcutController.cpp
468 ${UNITY_SRC}/ShortcutController.h
469 ${UNITY_SRC}/ShortcutModel.cpp
470 ${UNITY_SRC}/ShortcutModel.h
471 ${UNITY_SRC}/ShortcutView.cpp
472 ${UNITY_SRC}/ShortcutView.h
473 ${UNITY_SRC}/StaticCairoText.cpp
474 ${UNITY_SRC}/StaticCairoText.h
475 ${UNITY_SRC}/UBusMessages.h
476 ${UNITY_SRC}/ubus-server.cpp
477 ${UNITY_SRC}/ubus-server.h
478 )
479
455find_package (OpenGL)480find_package (OpenGL)
456
457include_directories (${OPENGL_gl_INCDIRS})481include_directories (${OPENGL_gl_INCDIRS})
458add_library (glfuncloader SHARED482add_library (glfuncloader SHARED
459 ${CMAKE_CURRENT_SOURCE_DIR}/GLFuncLoader.cpp)483 ${CMAKE_CURRENT_SOURCE_DIR}/GLFuncLoader.cpp)
@@ -467,9 +491,8 @@
467target_link_libraries (screen-effect-fbo glfuncloader ${OPENGL_gl_LIBRARY})491target_link_libraries (screen-effect-fbo glfuncloader ${OPENGL_gl_LIBRARY})
468add_dependencies (screen-effect-fbo ${UNITY_API_VERSION})492add_dependencies (screen-effect-fbo ${UNITY_API_VERSION})
469493
470
471# Custom target to make all the other targets here, add your test to this list494# Custom target to make all the other targets here, add your test to this list
472add_custom_target(standalone-clients DEPENDS dash panel launcher switcher keyutil quicklist quicklist-visuals filters filter-bar preview-applicaiton preview-generic preview-music result-view dash-style bg-hash)495add_custom_target(standalone-clients DEPENDS dash panel launcher switcher keyutil quicklist quicklist-visuals filters filter-bar preview-applicaiton preview-generic preview-music result-view dash-style bg-hash shortcut-view)
473496
474497
475498
476499
=== added file 'standalone-clients/TestShortcut.cpp'
--- standalone-clients/TestShortcut.cpp 1970-01-01 00:00:00 +0000
+++ standalone-clients/TestShortcut.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,109 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#include <dbus/dbus-glib.h>
21#include <glib/gi18n-lib.h>
22#include <gtk/gtk.h>
23#include <Nux/Nux.h>
24#include <Nux/WindowThread.h>
25
26#include "BackgroundEffectHelper.h"
27#include "MockShortcutHint.h"
28#include "ShortcutController.h"
29
30using namespace unity;
31
32static shortcut::Controller::Ptr controller;
33
34void ThreadWidgetInit(nux::NThread* thread, void* InitData)
35{
36 std::list<shortcut::AbstractHint*> hints;
37
38 // Launcher...
39 hints.push_back(new shortcut::MockHint(_("Launcher"), "", _(" (Press)"), _("Open Launcher, displays shortcuts."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher" ));
40 hints.push_back(new shortcut::MockHint(_("Launcher"), "", "", _("Open Launcher keyboard navigation mode."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "keyboard_focus"));
41 // FIXME: Implement it...
42 hints.push_back(new shortcut::MockHint(_("Launcher"), "", "", _("Switch application via Launcher."), shortcut::HARDCODED_OPTION, "Super + Tab"));
43 hints.push_back(new shortcut::MockHint(_("Launcher"), "", _(" + 1 to 9"), _("Same as clicking on a Launcher icon."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
44 hints.push_back(new shortcut::MockHint(_("Launcher"), "", _(" + Shift + 1 to 9"), _("Open a new window of the app."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
45 hints.push_back(new shortcut::MockHint(_("Launcher"), "", " + T", _("Open the Rubbish Bin."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
46
47 // Dash...
48 hints.push_back(new shortcut::MockHint(_("Dash"), "", _(" (Tap)"), _("Open the Dash Home."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
49 // These are not really hardcoded...
50 hints.push_back(new shortcut::MockHint(_("Dash"), "", " + A", _("Open the Dash App Lens."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
51 hints.push_back(new shortcut::MockHint(_("Dash"), "", " + F", _("Open the Dash Files Lens."), shortcut::COMPIZ_KEY_OPTION,"unityshell", "show_launcher"));
52 hints.push_back(new shortcut::MockHint(_("Dash"), "", " + M", _("Open the Dash Music Lens."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
53 hints.push_back(new shortcut::MockHint(_("Dash"), "", "", _("Switches between Lenses."), shortcut::HARDCODED_OPTION, "Ctrl + Tab"));
54 hints.push_back(new shortcut::MockHint(_("Dash"), "", "", _("Moves the focus."), shortcut::HARDCODED_OPTION, _("Cursor Keys")));
55 hints.push_back(new shortcut::MockHint(_("Dash"), "", "", _("Open currently focused item."), shortcut::HARDCODED_OPTION, _("Enter / Return")));
56 hints.push_back(new shortcut::MockHint(_("Dash"), "", "", _("'Run Command' mode."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "execute_command"));
57
58 // Top Bar
59 // Is it really hard coded?
60 hints.push_back(new shortcut::MockHint(_("Top Bar"), "", "", _("Reveals application menu."), shortcut::HARDCODED_OPTION, "Alt"));
61 hints.push_back(new shortcut::MockHint(_("Top Bar"), "", "", _("Opens the indicator menu."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "panel_first_menu"));
62 hints.push_back(new shortcut::MockHint(_("Top Bar"), "", "", _("Moves focus between indicators."), shortcut::HARDCODED_OPTION, _("Cursor Left & Right")));
63
64 // Switching
65 hints.push_back(new shortcut::MockHint(_("Switching"), "", "", _("Switch between applications."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_forward"));
66 hints.push_back(new shortcut::MockHint(_("Switching"), "", "", _("Switch windows of current application."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_next_window"));
67 hints.push_back(new shortcut::MockHint(_("Switching"), "", "", _("Close window switch, return to app switch."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_detail_stop"));
68 hints.push_back(new shortcut::MockHint(_("Switching"), "", "", _("Moves the foucs."), shortcut::HARDCODED_OPTION, _("Cursor Left & Right")));
69
70 // Workspaces
71 hints.push_back(new shortcut::MockHint(_("Workspaces"), "", "", _("Spread workspaces."), shortcut::COMPIZ_KEY_OPTION, "expo", "expo_key"));
72 hints.push_back(new shortcut::MockHint(_("Workspaces"), "", "", _("Switch workspaces."), shortcut::HARDCODED_OPTION, _("Cursor Keys")));
73 //hints.push_back(new shortcut::MockHint(_("Workspaces"), "", "", _("Move focused window to other workspace."), ...)
74
75 // Windows
76 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Spreads all windows in current workspace."), shortcut::COMPIZ_KEY_OPTION, "scale", "initiate_output_key"));
77 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Minimises all windows."), shortcut::COMPIZ_KEY_OPTION, "core", "show_desktop_key"));
78 // I don't know if it is really hardcoded, but I can't find where this option is stored.
79 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Open window accessibility menu."), shortcut::HARDCODED_OPTION, "Alt+Space"));
80 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Maximises current window."), shortcut::COMPIZ_KEY_OPTION, "core", "maximize_window_key"));
81 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Un-maximises current window."), shortcut::COMPIZ_KEY_OPTION, "core", "unmaximize_window_key"));
82 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Minimises current window."), shortcut::COMPIZ_KEY_OPTION, "core", "minimize_window_key"));
83 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Resizes current window."), shortcut::COMPIZ_KEY_OPTION, "resize", "initiate_key"));
84 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Closes current window."), shortcut::COMPIZ_KEY_OPTION, "core", "close_window_key"));
85 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Places window in corresponding positions."), shortcut::HARDCODED_OPTION, "Ctrl + Alt + Num"));
86 hints.push_back(new shortcut::MockHint(_("Windows"), "", "", _("Move window."), shortcut::COMPIZ_KEY_OPTION, "move", "initiate_key"));
87
88 controller.reset(new shortcut::Controller(hints));
89 controller->SetWorkspace(nux::Geometry(25, 17, 1200 - 50, 720 - 35));
90 controller->Show();
91}
92
93int main(int argc, char** argv)
94{
95 g_type_init();
96 //g_thread_init(NULL);
97 gtk_init(&argc, &argv);
98
99 dbus_g_thread_init();
100
101 nux::NuxInitialize(0);
102
103 BackgroundEffectHelper::blur_type = BLUR_NONE;
104 nux::WindowThread* wt = nux::CreateGUIThread(TEXT("Unity Shortcut Hint Overlay"), 1200, 720, 0, &ThreadWidgetInit, 0);
105
106 wt->Run(NULL);
107 delete wt;
108 return 0;
109}
0110
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2011-12-22 06:27:26 +0000
+++ tests/CMakeLists.txt 2012-01-13 15:39:27 +0000
@@ -70,7 +70,6 @@
70 ${UNITY_SRC}/70 ${UNITY_SRC}/
71 )71 )
72add_dependencies (test-unit unity-core-${UNITY_API_VERSION})72add_dependencies (test-unit unity-core-${UNITY_API_VERSION})
73
74add_subdirectory (test-input-remover)73add_subdirectory (test-input-remover)
75add_subdirectory (test-minimize-window-handler)74add_subdirectory (test-minimize-window-handler)
76add_subdirectory (test-get-transients)75add_subdirectory (test-get-transients)
@@ -107,6 +106,7 @@
107 test_service_model.h)106 test_service_model.h)
108 add_dependencies (test-gtest-service unity-core-${UNITY_API_VERSION})107 add_dependencies (test-gtest-service unity-core-${UNITY_API_VERSION})
109108
109
110# The actual test executable (xless) - do not put anything that requires X in here110# The actual test executable (xless) - do not put anything that requires X in here
111 add_executable(test-gtest-xless111 add_executable(test-gtest-xless
112 test_animator.cpp112 test_animator.cpp
@@ -118,10 +118,13 @@
118 test_glib_signals_utils.h118 test_glib_signals_utils.h
119 ${CMAKE_CURRENT_BINARY_DIR}/test_glib_signals_utils_marshal.cpp119 ${CMAKE_CURRENT_BINARY_DIR}/test_glib_signals_utils_marshal.cpp
120 test_favorite_store_gsettings.cpp120 test_favorite_store_gsettings.cpp
121 test_shortcut_model.cpp
122 test_shortcut_private.cpp
121 test_introspection.cpp123 test_introspection.cpp
122 test_main_xless.cpp124 test_main_xless.cpp
123 test_grabhandle.cpp125 test_grabhandle.cpp
124 ${UNITY_SRC}/AbstractLauncherIcon.h126 ${UNITY_SRC}/AbstractLauncherIcon.h
127 ${UNITY_SRC}/AbstractShortcutHint.h
125 ${UNITY_SRC}/Animator.cpp128 ${UNITY_SRC}/Animator.cpp
126 ${UNITY_SRC}/Animator.h129 ${UNITY_SRC}/Animator.h
127 ${UNITY_SRC}/DebugDBusInterface.h130 ${UNITY_SRC}/DebugDBusInterface.h
@@ -133,6 +136,11 @@
133 ${UNITY_SRC}/FavoriteStoreGSettings.cpp136 ${UNITY_SRC}/FavoriteStoreGSettings.cpp
134 ${UNITY_SRC}/FavoriteStoreGSettings.h137 ${UNITY_SRC}/FavoriteStoreGSettings.h
135 ${UNITY_SRC}/MockLauncherIcon.h138 ${UNITY_SRC}/MockLauncherIcon.h
139 ${UNITY_SRC}/MockShortcutHint.h
140 ${UNITY_SRC}/ShortcutModel.cpp
141 ${UNITY_SRC}/ShortcutModel.h
142 ${UNITY_SRC}/ShortcutHintPrivate.cpp
143 ${UNITY_SRC}/ShortcutHintPrivate.h
136 ${UNITY_SRC}/SwitcherModel.cpp144 ${UNITY_SRC}/SwitcherModel.cpp
137 ${UNITY_SRC}/SwitcherModel.h145 ${UNITY_SRC}/SwitcherModel.h
138 ${UNITY_SRC}/Introspectable.cpp146 ${UNITY_SRC}/Introspectable.cpp
139147
=== added file 'tests/test_shortcut_model.cpp'
--- tests/test_shortcut_model.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_shortcut_model.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,84 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#include <gtest/gtest.h>
21
22#include "MockShortcutHint.h"
23#include "ShortcutModel.h"
24
25using namespace unity::shortcut;
26
27namespace {
28
29TEST(TestShortcutModel, TestConstruction)
30{
31 std::list<AbstractHint*> hints;
32
33 hints.push_back(new MockHint("Launcher", "", "", "Description 1", COMPIZ_KEY_OPTION, "Plugin 1", "key_option_1"));
34 hints.push_back(new MockHint("Launcher", "", "", "Description 2", HARDCODED_OPTION, "Value 2"));
35 hints.push_back(new MockHint("Dash", "Prefix", "Postfix", "Description 3", COMPIZ_KEY_OPTION, "Plugin 3", "key_option_3"));
36 hints.push_back(new MockHint("Top Bar", "Prefix", "Postfix", "Description 4", HARDCODED_OPTION, "Value4"));
37
38 Model model(hints);
39
40 EXPECT_EQ(model.categories().size(), 3);
41 EXPECT_EQ(model.hints()["Launcher"].size(), 2);
42 EXPECT_EQ(model.hints()["Dash"].size(), 1);
43 EXPECT_EQ(model.hints()["Top Bar"].size(), 1);
44 EXPECT_EQ(model.hints()["Unity"].size(), 0);
45}
46
47TEST(TestShortcutModel, TestFill)
48{
49 std::list<AbstractHint*> hints;
50
51 hints.push_back(new MockHint("Launcher", "", "", "Description 1", COMPIZ_KEY_OPTION, "Plugin 1", "key_option_1"));
52 hints.push_back(new MockHint("Launcher", "", "", "Description 2", HARDCODED_OPTION, "Value 2"));
53 hints.push_back(new MockHint("Dash", "Prefix", "Postfix", "Description 3", COMPIZ_KEY_OPTION, "Plugin 3", "key_option_3"));
54 hints.push_back(new MockHint("Top Bar", "Prefix", "Postfix", "Description 4", HARDCODED_OPTION, "Value 4"));
55
56 Model model(hints);
57
58 model.Fill();
59
60 // We cannot test CompOption here... :/
61 EXPECT_EQ(model.hints()["Launcher"].front()->value(), "Plugin 1-key_option_1");
62 EXPECT_EQ(model.hints()["Launcher"].back()->value(), "Value 2");
63 EXPECT_EQ(model.hints()["Dash"].front()->value(),"Plugin 3-key_option_3");
64 EXPECT_EQ(model.hints()["Top Bar"].front()->value(), "Value 4");
65}
66
67TEST(TestShortcutModel, TestProperty)
68{
69 std::list<AbstractHint*> hints;
70
71 hints.push_back(new MockHint("Launcher", "Prefix1", "Postfix1", "Description1", COMPIZ_KEY_OPTION, "Plugin1", "key_option1"));
72
73 Model model(hints);
74
75 EXPECT_EQ(model.hints()["Launcher"].front()->category(), "Launcher");
76 EXPECT_EQ(model.hints()["Launcher"].front()->prefix(), "Prefix1");
77 EXPECT_EQ(model.hints()["Launcher"].front()->postfix(), "Postfix1");
78 EXPECT_EQ(model.hints()["Launcher"].front()->description(), "Description1");
79 EXPECT_EQ(model.hints()["Launcher"].front()->type(), COMPIZ_KEY_OPTION);
80 EXPECT_EQ(model.hints()["Launcher"].front()->arg1(), "Plugin1");
81 EXPECT_EQ(model.hints()["Launcher"].front()->arg2(), "key_option1");
82}
83
84} // anonymouse namespace
085
=== added file 'tests/test_shortcut_private.cpp'
--- tests/test_shortcut_private.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_shortcut_private.cpp 2012-01-13 15:39:27 +0000
@@ -0,0 +1,74 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 */
19
20#include <gtest/gtest.h>
21
22#include "ShortcutHintPrivate.h"
23
24using namespace unity::shortcut::impl;
25
26namespace {
27
28TEST(TestShortcutHintPrivate, TestFixShortcutFormatCorrect)
29{
30 EXPECT_EQ(FixShortcutFormat("Super"), "Super");
31 EXPECT_EQ(FixShortcutFormat("Super + A"), "Super + A");
32}
33
34
35TEST(TestShortcutHintPrivate, TestFixShortcutFormatLT)
36{
37 EXPECT_EQ(FixShortcutFormat("<Super"), "Super");
38 EXPECT_EQ(FixShortcutFormat("<Super + <Alt"), "Super + Alt");
39}
40
41TEST(TestShortcutHintPrivate, TestFixShortcutFormatGT)
42{
43 EXPECT_EQ(FixShortcutFormat("Super>"), "Super");
44 EXPECT_EQ(FixShortcutFormat("Super>A"), "Super + A");
45 EXPECT_EQ(FixShortcutFormat("Super>Alt>A"), "Super + Alt + A");
46}
47
48TEST(TestShortcutHintPrivate, TestFixShortcutComplete)
49{
50 EXPECT_EQ(FixShortcutFormat("Super"), "Super");
51 EXPECT_EQ(FixShortcutFormat("Super + A"), "Super + A");
52 EXPECT_EQ(FixShortcutFormat("<Super>"), "Super");
53 EXPECT_EQ(FixShortcutFormat("<Super>A"), "Super + A");
54 EXPECT_EQ(FixShortcutFormat("<Super><Alt>A"), "Super + Alt + A");
55}
56
57TEST(TestShortcutHintPrivate, TestProperCase)
58{
59 EXPECT_EQ(ProperCase("super"), "Super");
60 EXPECT_EQ(ProperCase("sUper"), "SUper");
61 EXPECT_EQ(ProperCase("super + a"), "Super + A");
62 EXPECT_EQ(ProperCase("super+a"), "Super+A");
63 EXPECT_EQ(ProperCase("<super><alt>a"), "<Super><Alt>A");
64}
65
66TEST(TestShortcutHintPrivate, TestFixMouseShortcut)
67{
68 EXPECT_EQ(FixMouseShortcut("Super<Button1>"), "Super<Left Mouse>");
69 EXPECT_EQ(FixMouseShortcut("Super<Button2>"), "Super<Middle Mouse>");
70 EXPECT_EQ(FixMouseShortcut("Super<Button3>"), "Super<Right Mouse>");
71
72}
73
74} // anonymouse namespace