Merge lp:~mterry/unity/683735 into lp:unity

Proposed by Michael Terry
Status: Merged
Merge reported by: Neil J. Patel
Merged at revision: not available
Proposed branch: lp:~mterry/unity/683735
Merge into: lp:unity
Diff against target: 138 lines (+47/-4)
6 files modified
CMakeLists.txt (+1/-1)
src/BamfLauncherIcon.cpp (+7/-3)
src/PluginAdapter.cpp (+30/-0)
src/PluginAdapter.h (+4/-0)
src/SimpleLauncherIcon.cpp (+3/-0)
src/TrashLauncherIcon.cpp (+2/-0)
To merge this branch: bzr merge lp:~mterry/unity/683735
Reviewer Review Type Date Requested Status
Sam Spilsbury (community) Approve
Review via email: mp+42406@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote :

Patch works nicely. Maybe it'd be good to check the scale action's state before calling terminate? It doesn't crash the way it is, but it would save a little bit of overhead.

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Yeah alex is right. Basically just do an if (m_ScaleAction->state () & (CompAction::StateTermKey | CompAction::StateTermButton)) terminate ();

Revision history for this message
Michael Terry (mterry) wrote :

I've modified the code to:
 * Terminate the scale if any launcher icon is clicked, not just running bamf icons
 * Does not scale again if the user clicks on the same bamf launcher while scaled
 * Does not terminate scale if we aren't scaled

In order to determine if we're scaled, I could not use your state() code, Same. The only thing that worked for me was actually getting the plugin class and asking if it had the grab. The action object itself just didn't have the information. The state() function always returned the same state. Which I could have fixed by passing StateInitButton when initializing the scale, but even so, it would only work when checking for scaling done by that same action. If the user pressed Super+A, they would get a scale that couldn't be terminated by launcher clicks, though I think it should be.

So, I linked against the scale plugin and checked its status directly.

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

That's strange the state () should reflect what is there of the action (since the scale plugin does action->setState ().

Maybe the initial state isn't set to StateInitKey, in which case you'll need to force that (eg m_ScaleAction->setState (CompAction::StateInitKey); before actually initiating it

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Oh, pass StateInitKey | StateInitButton. That should do it. core doesn't really care what state the action is in, it only sets those things so that the plugins can respond appropriately.

Revision history for this message
Michael Terry (mterry) wrote :

Right... As I said, "I could have fixed by passing StateInitButton when initializing the scale, but even so, it would only work when checking for scaling done by that same action. If the user pressed Super+A, they would get a scale that couldn't be terminated by launcher clicks, though I think it should be. So, I linked against the scale plugin and checked its status directly."

There's a difference between checking the action's state and the plugin's state.

Revision history for this message
Alex Launi (alexlauni) wrote :

You can pass StateInitKey | StateInitButton. That should handle the Super + A case.

Revision history for this message
Michael Terry (mterry) wrote :

Actually, in my testing the plugin only handles state like we want if we pass just StateInitButton. Passing in StateInitKey (either additionally or by itself) doens't change the results of state() calls.

Even if we did pass them both in, my point was that the action/plugin relationship was multiple-to-one (as I understand it, I may be totally wrong). So just checking the state of one action is not sufficient as you don't know what other actions are doing. So you have to go to the source, the plugin. That's why we can't handle Super+A without checking the plugin.

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Huh. My impression was that it worked differently. I'll check the code, sec

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Ah yes, the problem is that there is one CompAction * per CompOption *, which means that there is one CompAction * for initiate_key, initiate_button and initiate_edge, as well as initiate_all_* initiate_group_* etc

I guess this means you'll have to store all the actions and check all
of their states and fire the actions appropriately (eg don't initiate if one of them is already on StateTerminateKey | StateTerminateButton | StateTerminateEdge)

Since the fix is *fairly* non-trivial I will merge it for now and finish it myself tonight. Thanks for all your help Michael :)

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

Thanks for updating the branch, it's merged now!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2010-12-09 18:02:17 +0000
3+++ CMakeLists.txt 2010-12-13 23:35:23 +0000
4@@ -80,7 +80,7 @@
5 include (CompizPlugin)
6 compiz_plugin (unityshell
7 PKGDEPS ${UNITY_PLUGIN_DEPS}
8- PLUGINDEPS composite opengl
9+ PLUGINDEPS composite opengl scale
10 CFLAGSADD "-DINSTALLPREFIX='\"${CMAKE_INSTALL_PREFIX}\"' -DPKGDATADIR='\"${CMAKE_INSTALL_PREFIX}/share/unity/3\"' -I${CMAKE_BINARY_DIR}"
11 LIBRARIES "unity"
12 )
13
14=== modified file 'src/BamfLauncherIcon.cpp'
15--- src/BamfLauncherIcon.cpp 2010-12-13 22:50:48 +0000
16+++ src/BamfLauncherIcon.cpp 2010-12-13 23:35:23 +0000
17@@ -306,6 +306,10 @@
18 void
19 BamfLauncherIcon::OnMouseClick (int button)
20 {
21+ bool scaleWasActive = PluginAdapter::Default ()->IsScaleActive();
22+
23+ SimpleLauncherIcon::OnMouseClick (button);
24+
25 if (button != 1)
26 return;
27
28@@ -322,10 +326,10 @@
29 OpenInstance ();
30 return;
31 }
32- else if (active)
33+ else if (!active)
34+ Focus ();
35+ else if (!scaleWasActive)
36 Spread ();
37- else
38- Focus ();
39 }
40
41 void
42
43=== modified file 'src/PluginAdapter.cpp'
44--- src/PluginAdapter.cpp 2010-11-10 15:45:18 +0000
45+++ src/PluginAdapter.cpp 2010-12-13 23:35:23 +0000
46@@ -17,6 +17,7 @@
47 */
48
49 #include <glib.h>
50+#include <scale/scale.h>
51 #include "PluginAdapter.h"
52
53 PluginAdapter * PluginAdapter::_default = 0;
54@@ -111,6 +112,35 @@
55 m_ScaleAction->initiate () (m_ScaleAction, 0, argument);
56 }
57
58+bool
59+PluginAdapter::IsScaleActive ()
60+{
61+ SCALE_SCREEN(m_Screen);
62+ return (m_ScaleAction && ss && ss->hasGrab ());
63+}
64+
65+void
66+PluginAdapter::TerminateScale ()
67+{
68+ if (!IsScaleActive ())
69+ return;
70+
71+ CompOption::Value value;
72+ CompOption::Type type;
73+ CompOption::Vector argument;
74+ char *name;
75+
76+ name = (char *) "root";
77+ type = CompOption::TypeInt;
78+ value.set ((int) m_Screen->root ());
79+
80+ CompOption arg = CompOption (name, type);
81+ arg.set (value);
82+ argument.push_back (arg);
83+
84+ m_ScaleAction->terminate () (m_ScaleAction, 0, argument);
85+}
86+
87 void
88 PluginAdapter::InitiateExpo ()
89 {
90
91=== modified file 'src/PluginAdapter.h'
92--- src/PluginAdapter.h 2010-11-10 14:42:46 +0000
93+++ src/PluginAdapter.h 2010-12-13 23:35:23 +0000
94@@ -40,6 +40,10 @@
95 void SetExpoAction (CompAction *expo);
96
97 void InitiateScale (std::string *match);
98+
99+ bool IsScaleActive ();
100+
101+ void TerminateScale ();
102
103 void InitiateExpo ();
104
105
106=== modified file 'src/SimpleLauncherIcon.cpp'
107--- src/SimpleLauncherIcon.cpp 2010-12-06 20:12:06 +0000
108+++ src/SimpleLauncherIcon.cpp 2010-12-13 23:35:23 +0000
109@@ -21,6 +21,7 @@
110
111 #include "SimpleLauncherIcon.h"
112 #include "Launcher.h"
113+#include "PluginAdapter.h"
114
115 SimpleLauncherIcon::SimpleLauncherIcon (Launcher* IconManager)
116 : LauncherIcon(IconManager)
117@@ -54,6 +55,8 @@
118 void
119 SimpleLauncherIcon::OnMouseClick (int button)
120 {
121+ if (button == 1)
122+ PluginAdapter::Default ()->TerminateScale ();
123 }
124
125 void
126
127=== modified file 'src/TrashLauncherIcon.cpp'
128--- src/TrashLauncherIcon.cpp 2010-12-07 18:14:21 +0000
129+++ src/TrashLauncherIcon.cpp 2010-12-13 23:35:23 +0000
130@@ -50,6 +50,8 @@
131 void
132 TrashLauncherIcon::OnMouseClick (int button)
133 {
134+ SimpleLauncherIcon::OnMouseClick (button);
135+
136 if (button == 1)
137 {
138 GError *error = NULL;