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
1=== modified file 'plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h'
2--- plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h 2013-10-31 15:59:14 +0000
3+++ plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h 2015-08-22 21:54:12 +0000
4@@ -63,7 +63,7 @@
5 AllViewports,
6 Panels,
7 Group
8-} SwitchWindowSelection;
9+} SwitchWindowSelection;
10
11 class BaseSwitchScreen
12 {
13@@ -75,6 +75,7 @@
14 void setSelectedWindowHint (bool focus);
15 void activateEvent (bool activating);
16 void updateForegroundColor ();
17+ void updateBackground (bool useBackgroundColor, unsigned short backgroundColor[]);
18
19 CompWindow *switchToWindow (bool toNext, bool autoChangeVPOption, bool focus);
20 static bool compareWindows (CompWindow *w1, CompWindow *w2);
21
22=== modified file 'plugins/compiztoolbox/src/compiztoolbox.cpp'
23--- plugins/compiztoolbox/src/compiztoolbox.cpp 2013-05-12 08:13:05 +0000
24+++ plugins/compiztoolbox/src/compiztoolbox.cpp 2015-08-22 21:54:12 +0000
25@@ -124,6 +124,24 @@
26 return "";
27 }
28
29+void
30+BaseSwitchScreen::updateBackground(bool useBackgroundColor,
31+ unsigned short backgroundColor[])
32+{
33+ if (!popupWindow)
34+ return;
35+
36+ unsigned long background_pixel = 0ul;
37+ if (useBackgroundColor)
38+ {
39+ background_pixel = ((((static_cast<unsigned long>(backgroundColor [3]) * backgroundColor [2]) >> 24) & 0x0000ff) |
40+ (((backgroundColor [3] * backgroundColor [1]) >> 16) & 0x00ff00) |
41+ (((backgroundColor [3] * backgroundColor [0]) >> 8) & 0xff0000) |
42+ (((backgroundColor [3] & 0xff00) << 16)));
43+ }
44+
45+ XSetWindowBackground (screen->dpy(), popupWindow, background_pixel);
46+}
47
48 void
49 BaseSwitchScreen::setSelectedWindowHint (bool focus)
50
51=== modified file 'plugins/staticswitcher/src/staticswitcher.cpp'
52--- plugins/staticswitcher/src/staticswitcher.cpp 2013-06-11 04:45:57 +0000
53+++ plugins/staticswitcher/src/staticswitcher.cpp 2015-08-22 21:54:12 +0000
54@@ -286,6 +286,7 @@
55 (unsigned char *) &Atoms::winTypeUtil, 1);
56
57 ::screen->setWindowProp (popupWindow, Atoms::winDesktop, 0xffffffff);
58+ updateBackground(optionGetUseBackgroundColor(), optionGetBackgroundColor());
59
60 setSelectedWindowHint (false);
61
62@@ -1357,6 +1358,10 @@
63 move (0),
64 mouseSelect (false)
65 {
66+ auto bgUpdater = [=] (...){ this->updateBackground (this->optionGetUseBackgroundColor (), this->optionGetBackgroundColor ());};
67+ optionSetUseBackgroundColorNotify (bgUpdater);
68+ optionSetBackgroundColorNotify (bgUpdater);
69+
70 #define SWITCHBIND(a,b,c) boost::bind (switchInitiateCommon, _1, _2, _3, a, b, c)
71
72 optionSetNextButtonInitiate (SWITCHBIND (CurrentViewport, true, true));
73
74=== modified file 'plugins/staticswitcher/staticswitcher.xml.in'
75--- plugins/staticswitcher/staticswitcher.xml.in 2012-10-15 10:31:51 +0000
76+++ plugins/staticswitcher/staticswitcher.xml.in 2015-08-22 21:54:12 +0000
77@@ -293,6 +293,24 @@
78 </default>
79 </option>
80 </subgroup>
81+ <subgroup>
82+ <_short>Background</_short>
83+ <option name="use_background_color" type="bool">
84+ <_short>Set background color</_short>
85+ <_long>Set background color</_long>
86+ <default>false</default>
87+ </option>
88+ <option name="background_color" type="color">
89+ <_short>Background Color</_short>
90+ <_long>Background color of the switcher window.</_long>
91+ <default>
92+ <red>0x3333</red>
93+ <green>0x3333</green>
94+ <blue>0x3333</blue>
95+ <alpha>0xd998</alpha>
96+ </default>
97+ </option>
98+ </subgroup>
99 </group>
100 </options>
101 </plugin>
102
103=== modified file 'plugins/switcher/src/switcher.cpp'
104--- plugins/switcher/src/switcher.cpp 2015-07-25 20:01:51 +0000
105+++ plugins/switcher/src/switcher.cpp 2015-08-22 21:54:12 +0000
106@@ -66,7 +66,6 @@
107 (WIDTH >> 1), HEIGHT - BOX_WIDTH, 0.0f,
108 };
109
110-
111 void
112 SwitchScreen::updateWindowList (int count)
113 {
114@@ -300,6 +299,7 @@
115 (unsigned char *) &Atoms::winTypeUtil, 1);
116
117 screen->setWindowProp (popupWindow, Atoms::winDesktop, 0xffffffff);
118+ updateBackground (optionGetUseBackgroundColor (), optionGetBackgroundColor ());
119
120 setSelectedWindowHint (false);
121 }
122@@ -1123,6 +1123,10 @@
123
124 optionSetZoomNotify (boost::bind (&SwitchScreen::setZoom, this));
125
126+ auto bgUpdater = [=] (...){ this->updateBackground (this->optionGetUseBackgroundColor (), this->optionGetBackgroundColor ());};
127+ optionSetUseBackgroundColorNotify (bgUpdater);
128+ optionSetBackgroundColorNotify (bgUpdater);
129+
130 #define SWITCHBIND(a,b,c) boost::bind (switchInitiateCommon, _1, _2, _3, a, b, c)
131
132 optionSetNextButtonInitiate (SWITCHBIND (CurrentViewport, true, true));
133
134=== modified file 'plugins/switcher/switcher.xml.in'
135--- plugins/switcher/switcher.xml.in 2012-10-15 10:31:51 +0000
136+++ plugins/switcher/switcher.xml.in 2015-08-22 21:54:12 +0000
137@@ -166,6 +166,24 @@
138 <_long>Rotate to the selected window while switching</_long>
139 <default>false</default>
140 </option>
141+ <subgroup>
142+ <_short>Background</_short>
143+ <option name="use_background_color" type="bool">
144+ <_short>Set background color</_short>
145+ <_long>Set background color</_long>
146+ <default>false</default>
147+ </option>
148+ <option name="background_color" type="color">
149+ <_short>Background Color</_short>
150+ <_long>Background color of the switcher window.</_long>
151+ <default>
152+ <red>0x3333</red>
153+ <green>0x3333</green>
154+ <blue>0x3333</blue>
155+ <alpha>0xd998</alpha>
156+ </default>
157+ </option>
158+ </subgroup>
159 </options>
160 </plugin>
161 </compiz>

Subscribers

People subscribed via source and target branches