Merge lp:~nwkj86/compiz/add-background-conf-to-switcher into lp:compiz/0.9.12

Proposed by Artur
Status: Merged
Approved by: MC Return
Approved revision: 3974
Merged at revision: 3975
Proposed branch: lp:~nwkj86/compiz/add-background-conf-to-switcher
Merge into: lp:compiz/0.9.12
Diff against target: 161 lines (+66/-2)
6 files modified
plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h (+2/-1)
plugins/compiztoolbox/src/compiztoolbox.cpp (+18/-0)
plugins/staticswitcher/src/staticswitcher.cpp (+5/-0)
plugins/staticswitcher/staticswitcher.xml.in (+18/-0)
plugins/switcher/src/switcher.cpp (+5/-1)
plugins/switcher/switcher.xml.in (+18/-0)
To merge this branch: bzr merge lp:~nwkj86/compiz/add-background-conf-to-switcher
Reviewer Review Type Date Requested Status
MC Return Approve
Review via email: mp+268556@code.launchpad.net

Commit message

Allow to select background color for switcher and staticswitcher.

Description of the change

Allow user to set & select background color for switcher and staticswitcher.

Right now setBackground() function is duplicated. I'm looking for the good common place to put it there.

To post a comment you must log in.
Revision history for this message
MC Return (mc-return) wrote :

Hey Artur,
Thanks for your contribution.

Here a review:

1. You need to click "Set commit message" on this page above and enter a commit message there, otherwise this won't merge correctly.

2. A good common place to put setBackground () to would be the BaseSwitchScreen class in compiztoolbox.cpp to avoid code duplication.
You could then use the optionGet () variables as function arguments in your setBackground () function and pass those via update notification to your function like this:

    optionSetUseBackgroundColorNotify (boost::bind (&BaseSwitchScreen::updateBackground, this, optionGetUseBackgroundColor (), optionGetBackgroundColor ()));
    optionSetBackgroundColorNotify (boost::bind (&BaseSwitchScreen::updateBackground, this, optionGetUseBackgroundColor (), optionGetBackgroundColor ()));

The function in BaseSwitchScreen could then look like this:
void
BaseSwitchScreen::updateBackground (bool useBackgoundColor,
        unsigned short backgroundColor [])

3. unsigned short alpha seems to be unused. I know XColor does not care about transparency, but it would be nice if the alpha value would not be ignored, so semi-transparency of the background would also be possible...

4. Please insert a whitespace between function name and brackets as this is the style Compiz (mostly ;)) uses.

5. Typo here: 87 + <_short>Bacground Color</_short>

6. It seems that once the background color has been enabled, it cannot be disabled anymore - setting unsigned long background_pixel = 0ul; seems not to be enough to reset the background back...
Also you should not set background_pixel to 0ul in any case as this value gets overwritten before usage anyway in the case the background color gets used...
Does disabling the background color work for you ?

Revision history for this message
Artur (nwkj86) wrote :

Wow. Thank you a lot for your comment. I'll apply your suggestions and try to make this change in the right way. I'll push something soon.

About 6: I'm setting background_pixel = 0, because *switcher is doing that in original version. Yes, unchecking EnableBackground option resets it to be transparent (as before my changes).

Revision history for this message
MC Return (mc-return) wrote :

> About 6: I'm setting background_pixel = 0, because *switcher is doing that in
> original version. Yes, unchecking EnableBackground option resets it to be
> transparent (as before my changes).

Yeah, it was only my first test version, which did not update the useBackgroundColor bool correctly - I had to fix this by manually updating this bool shortly after creation of the popup window (hint if you experience the same problem).

Here the improved version for the updateBackground function, now also using some magic to factor in transparency into background_pixel, maybe you want to use it:

void
BaseSwitchScreen::updateBackground (bool useBackgroundColor,
        unsigned short backgroundColor [])
{
    if (!popupWindow)
 return;

    unsigned long background_pixel;

    if (useBackgroundColor)
 background_pixel = (unsigned long)((((backgroundColor [3] * backgroundColor [2]) >> 24) & 0x0000ff) |
        (((backgroundColor [3] * backgroundColor [1]) >> 16) & 0x00ff00) |
        (((backgroundColor [3] * backgroundColor [0]) >> 8) & 0xff0000) |
        (((backgroundColor [3] & 0xff00) << 16)));
    else
 background_pixel = 0ul;

    XSetWindowBackground (screen->dpy (), popupWindow, background_pixel);
}

Revision history for this message
Artur (nwkj86) wrote :

Hi,

I think that problem with not updating background settings is caused by:

optionSetUseBackgroundColorNotify (boost::bind (&BaseSwitchScreen::updateBackground, this, optionGetUseBackgroundColor (), optionGetBackgroundColor ()));

optionGetBackgroundColor is binded once forever.

Consider:
#include <boost/bind.hpp>
#include <iostream>
using namespace std;
using namespace boost;
int getI()
{
  static int i;
  i++;
  cout << "getI() = " << i << endl;
  return i;
}
void printer(int i)
{
  cout << "printer(" << i << ")" << endl;
}
int main()
{
  auto p = bind(&printer, getI());
  p();
  p();
  p();
  return 0;
}

What should be printed?

BTW: is C++11 available in compiz?

Revision history for this message
Stephen M. Webb (bregma) wrote :

We recently switched to building with C++11 enabled because a dependency used by some plugins requires it. There is currently no C++11 code in Compiz itself but that may change in the near future.

Revision history for this message
Artur (nwkj86) wrote :

I don't see --std=c++11 (or similar) in main CMakeLists.txt, but I see it in compizconfig/ and in debian/rules.

I'm on bzr+ssh://bazaar.launchpad.net/~compiz-team/compiz/0.9.12/ branch.

I've added 'const auto &test = *this;' and I see

warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]

This code compiles when I add '-DCMAKE_CXX_FLAGS' to cmake command.

Am I doing something wrong?

Revision history for this message
Artur (nwkj86) wrote :

I meant: '-DCMAKE_CXX_FLAGS="--std=c++11"'.

Revision history for this message
Stephen M. Webb (bregma) wrote :

No, you're not doing anything wrong. The CMake recipes have not been updated to force C++-11 mode, just the Debian packaging. There's an MP floating around to fix the packaging.

3974. By Artur

Post review changes.

* change setBackground to updateBackground and move it to base class
* fix typo

Revision history for this message
MC Return (mc-return) wrote :

LGTM. +1

review: Approve
Revision history for this message
Artur (nwkj86) wrote :

Thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h'
--- plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h 2013-10-31 15:59:14 +0000
+++ plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h 2015-08-22 21:54:12 +0000
@@ -63,7 +63,7 @@
63 AllViewports,63 AllViewports,
64 Panels,64 Panels,
65 Group65 Group
66} SwitchWindowSelection; 66} SwitchWindowSelection;
6767
68class BaseSwitchScreen68class BaseSwitchScreen
69{69{
@@ -75,6 +75,7 @@
75 void setSelectedWindowHint (bool focus);75 void setSelectedWindowHint (bool focus);
76 void activateEvent (bool activating);76 void activateEvent (bool activating);
77 void updateForegroundColor ();77 void updateForegroundColor ();
78 void updateBackground (bool useBackgroundColor, unsigned short backgroundColor[]);
7879
79 CompWindow *switchToWindow (bool toNext, bool autoChangeVPOption, bool focus);80 CompWindow *switchToWindow (bool toNext, bool autoChangeVPOption, bool focus);
80 static bool compareWindows (CompWindow *w1, CompWindow *w2);81 static bool compareWindows (CompWindow *w1, CompWindow *w2);
8182
=== modified file 'plugins/compiztoolbox/src/compiztoolbox.cpp'
--- plugins/compiztoolbox/src/compiztoolbox.cpp 2013-05-12 08:13:05 +0000
+++ plugins/compiztoolbox/src/compiztoolbox.cpp 2015-08-22 21:54:12 +0000
@@ -124,6 +124,24 @@
124 return "";124 return "";
125}125}
126126
127void
128BaseSwitchScreen::updateBackground(bool useBackgroundColor,
129 unsigned short backgroundColor[])
130{
131 if (!popupWindow)
132 return;
133
134 unsigned long background_pixel = 0ul;
135 if (useBackgroundColor)
136 {
137 background_pixel = ((((static_cast<unsigned long>(backgroundColor [3]) * backgroundColor [2]) >> 24) & 0x0000ff) |
138 (((backgroundColor [3] * backgroundColor [1]) >> 16) & 0x00ff00) |
139 (((backgroundColor [3] * backgroundColor [0]) >> 8) & 0xff0000) |
140 (((backgroundColor [3] & 0xff00) << 16)));
141 }
142
143 XSetWindowBackground (screen->dpy(), popupWindow, background_pixel);
144}
127145
128void146void
129BaseSwitchScreen::setSelectedWindowHint (bool focus)147BaseSwitchScreen::setSelectedWindowHint (bool focus)
130148
=== modified file 'plugins/staticswitcher/src/staticswitcher.cpp'
--- plugins/staticswitcher/src/staticswitcher.cpp 2013-06-11 04:45:57 +0000
+++ plugins/staticswitcher/src/staticswitcher.cpp 2015-08-22 21:54:12 +0000
@@ -286,6 +286,7 @@
286 (unsigned char *) &Atoms::winTypeUtil, 1);286 (unsigned char *) &Atoms::winTypeUtil, 1);
287287
288 ::screen->setWindowProp (popupWindow, Atoms::winDesktop, 0xffffffff);288 ::screen->setWindowProp (popupWindow, Atoms::winDesktop, 0xffffffff);
289 updateBackground(optionGetUseBackgroundColor(), optionGetBackgroundColor());
289290
290 setSelectedWindowHint (false);291 setSelectedWindowHint (false);
291292
@@ -1357,6 +1358,10 @@
1357 move (0),1358 move (0),
1358 mouseSelect (false)1359 mouseSelect (false)
1359{1360{
1361 auto bgUpdater = [=] (...){ this->updateBackground (this->optionGetUseBackgroundColor (), this->optionGetBackgroundColor ());};
1362 optionSetUseBackgroundColorNotify (bgUpdater);
1363 optionSetBackgroundColorNotify (bgUpdater);
1364
1360#define SWITCHBIND(a,b,c) boost::bind (switchInitiateCommon, _1, _2, _3, a, b, c)1365#define SWITCHBIND(a,b,c) boost::bind (switchInitiateCommon, _1, _2, _3, a, b, c)
13611366
1362 optionSetNextButtonInitiate (SWITCHBIND (CurrentViewport, true, true));1367 optionSetNextButtonInitiate (SWITCHBIND (CurrentViewport, true, true));
13631368
=== modified file 'plugins/staticswitcher/staticswitcher.xml.in'
--- plugins/staticswitcher/staticswitcher.xml.in 2012-10-15 10:31:51 +0000
+++ plugins/staticswitcher/staticswitcher.xml.in 2015-08-22 21:54:12 +0000
@@ -293,6 +293,24 @@
293 </default>293 </default>
294 </option>294 </option>
295 </subgroup>295 </subgroup>
296 <subgroup>
297 <_short>Background</_short>
298 <option name="use_background_color" type="bool">
299 <_short>Set background color</_short>
300 <_long>Set background color</_long>
301 <default>false</default>
302 </option>
303 <option name="background_color" type="color">
304 <_short>Background Color</_short>
305 <_long>Background color of the switcher window.</_long>
306 <default>
307 <red>0x3333</red>
308 <green>0x3333</green>
309 <blue>0x3333</blue>
310 <alpha>0xd998</alpha>
311 </default>
312 </option>
313 </subgroup>
296 </group>314 </group>
297 </options>315 </options>
298 </plugin>316 </plugin>
299317
=== modified file 'plugins/switcher/src/switcher.cpp'
--- plugins/switcher/src/switcher.cpp 2015-07-25 20:01:51 +0000
+++ plugins/switcher/src/switcher.cpp 2015-08-22 21:54:12 +0000
@@ -66,7 +66,6 @@
66 (WIDTH >> 1), HEIGHT - BOX_WIDTH, 0.0f,66 (WIDTH >> 1), HEIGHT - BOX_WIDTH, 0.0f,
67};67};
6868
69
70void69void
71SwitchScreen::updateWindowList (int count)70SwitchScreen::updateWindowList (int count)
72{71{
@@ -300,6 +299,7 @@
300 (unsigned char *) &Atoms::winTypeUtil, 1);299 (unsigned char *) &Atoms::winTypeUtil, 1);
301300
302 screen->setWindowProp (popupWindow, Atoms::winDesktop, 0xffffffff);301 screen->setWindowProp (popupWindow, Atoms::winDesktop, 0xffffffff);
302 updateBackground (optionGetUseBackgroundColor (), optionGetBackgroundColor ());
303303
304 setSelectedWindowHint (false);304 setSelectedWindowHint (false);
305 }305 }
@@ -1123,6 +1123,10 @@
11231123
1124 optionSetZoomNotify (boost::bind (&SwitchScreen::setZoom, this));1124 optionSetZoomNotify (boost::bind (&SwitchScreen::setZoom, this));
11251125
1126 auto bgUpdater = [=] (...){ this->updateBackground (this->optionGetUseBackgroundColor (), this->optionGetBackgroundColor ());};
1127 optionSetUseBackgroundColorNotify (bgUpdater);
1128 optionSetBackgroundColorNotify (bgUpdater);
1129
1126#define SWITCHBIND(a,b,c) boost::bind (switchInitiateCommon, _1, _2, _3, a, b, c)1130#define SWITCHBIND(a,b,c) boost::bind (switchInitiateCommon, _1, _2, _3, a, b, c)
11271131
1128 optionSetNextButtonInitiate (SWITCHBIND (CurrentViewport, true, true));1132 optionSetNextButtonInitiate (SWITCHBIND (CurrentViewport, true, true));
11291133
=== modified file 'plugins/switcher/switcher.xml.in'
--- plugins/switcher/switcher.xml.in 2012-10-15 10:31:51 +0000
+++ plugins/switcher/switcher.xml.in 2015-08-22 21:54:12 +0000
@@ -166,6 +166,24 @@
166 <_long>Rotate to the selected window while switching</_long>166 <_long>Rotate to the selected window while switching</_long>
167 <default>false</default>167 <default>false</default>
168 </option>168 </option>
169 <subgroup>
170 <_short>Background</_short>
171 <option name="use_background_color" type="bool">
172 <_short>Set background color</_short>
173 <_long>Set background color</_long>
174 <default>false</default>
175 </option>
176 <option name="background_color" type="color">
177 <_short>Background Color</_short>
178 <_long>Background color of the switcher window.</_long>
179 <default>
180 <red>0x3333</red>
181 <green>0x3333</green>
182 <blue>0x3333</blue>
183 <alpha>0xd998</alpha>
184 </default>
185 </option>
186 </subgroup>
169 </options>187 </options>
170 </plugin>188 </plugin>
171</compiz>189</compiz>

Subscribers

People subscribed via source and target branches