Merge lp:~mc-return/compiz/compiz0.9.9.merge-plugin-startup into lp:compiz/0.9.9

Proposed by MC Return
Status: Superseded
Proposed branch: lp:~mc-return/compiz/compiz0.9.9.merge-plugin-startup
Merge into: lp:compiz/0.9.9
Diff against target: 432 lines (+400/-0)
5 files modified
debian/compiz-plugins.install (+1/-0)
plugins/startup/CMakeLists.txt (+5/-0)
plugins/startup/src/startup.cpp (+274/-0)
plugins/startup/src/startup.h (+75/-0)
plugins/startup/startup.xml.in (+45/-0)
To merge this branch: bzr merge lp:~mc-return/compiz/compiz0.9.9.merge-plugin-startup
Reviewer Review Type Date Requested Status
Compiz Maintainers Pending
Review via email: mp+142274@code.launchpad.net

This proposal has been superseded by a proposal from 2013-04-02.

Commit message

Added the plug-in "Startup" converted from git to bzr (including full history) to lp:compiz.

Description of the change

Another useful plugin lost in the realms of the git repo :)

What can this be used for, one might ask...

Example 1:
You want to autostart some widgets, which should use Compiz' widget layer plugin and reside on their own layer.
To achieve this you have to ensure those widgets start after Compiz (Best option: First Time).

Example 2:
You want to ensure some OpenGL program starts after Compiz, like a GL-dock for example.

To post a comment you must log in.
3296. By MC Return

Modified debian/compiz-plugins.install to also install the startup plugin

3297. By MC Return

Merged latest lp:compiz

3298. By MC Return

Fixed indentation
Use prefix instead of postfix increments
if (i == 0) -> if (!i)
C++ style for comments
Added newlines to improve readability

3299. By MC Return

Merged latest lp:compiz

3300. By MC Return

Fixed typo

3301. By MC Return

C++ style for comments
Fixed compilation (macro)

3302. By MC Return

Added . to comment

3303. By MC Return

Minor additional .xml improvements
(indentation, better tooltip)

3304. By MC Return

Merged latest lp:compiz

3305. By MC Return

Improved/harmonized ABI check

3306. By MC Return

Merged latest lp:compiz

Unmerged revisions

3306. By MC Return

Merged latest lp:compiz

3305. By MC Return

Improved/harmonized ABI check

3304. By MC Return

Merged latest lp:compiz

3303. By MC Return

Minor additional .xml improvements
(indentation, better tooltip)

3302. By MC Return

Added . to comment

3301. By MC Return

C++ style for comments
Fixed compilation (macro)

3300. By MC Return

Fixed typo

3299. By MC Return

Merged latest lp:compiz

3298. By MC Return

Fixed indentation
Use prefix instead of postfix increments
if (i == 0) -> if (!i)
C++ style for comments
Added newlines to improve readability

3297. By MC Return

Merged latest lp:compiz

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/compiz-plugins.install'
--- debian/compiz-plugins.install 2013-01-10 10:53:57 +0000
+++ debian/compiz-plugins.install 2013-01-31 19:35:25 +0000
@@ -39,6 +39,7 @@
39debian/tmp/usr/share/compiz/showmouse39debian/tmp/usr/share/compiz/showmouse
40debian/tmp/usr/*/compiz/*splash.*40debian/tmp/usr/*/compiz/*splash.*
41debian/tmp/usr/share/compiz/splash41debian/tmp/usr/share/compiz/splash
42debian/tmp/usr/*/compiz/*startup.*
42debian/tmp/usr/*/compiz/*showrepaint.*43debian/tmp/usr/*/compiz/*showrepaint.*
43debian/tmp/usr/*/compiz/*switcher.*44debian/tmp/usr/*/compiz/*switcher.*
44debian/tmp/usr/*/compiz/*td.*45debian/tmp/usr/*/compiz/*td.*
4546
=== added directory 'plugins/startup'
=== added file 'plugins/startup/CMakeLists.txt'
--- plugins/startup/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ plugins/startup/CMakeLists.txt 2013-01-31 19:35:25 +0000
@@ -0,0 +1,5 @@
1find_package (Compiz REQUIRED)
2
3include (CompizPlugin)
4
5compiz_plugin (startup PLUGINDEPS composite)
06
=== added directory 'plugins/startup/src'
=== added file 'plugins/startup/src/startup.cpp'
--- plugins/startup/src/startup.cpp 1970-01-01 00:00:00 +0000
+++ plugins/startup/src/startup.cpp 2013-01-31 19:35:25 +0000
@@ -0,0 +1,274 @@
1#include "startup.h"
2
3
4COMPIZ_PLUGIN_20090315 (startup, StartupPluginVTable);
5
6// mkdir_p: Creates a directory making parent directories as needed.
7// (same as mkdir -p)
8
9void
10mkdir_p(CompString &pathname)
11{
12 if (mkdir(pathname.c_str(), 0777) < 0)
13 {
14 // If we couldn't make the whole directory because of ENOENT (a
15 // parent directory doesn't exist), then try recursively to make
16 // the immediate parent directory.
17 if (errno == ENOENT)
18 {
19 size_t slash = pathname.rfind('/');
20 if (slash != CompString::npos)
21 {
22 CompString prefix = pathname.substr(0, slash);
23 mkdir_p(prefix);
24 mkdir(pathname.c_str(), 0777);
25 }
26 }
27 }
28}
29
30void
31StartupScreen::RunCommands()
32{
33 updateOptions();
34
35 if (numCommands < 1);
36 ranCommands = true;
37
38 for (int i = 0; i < numCommands; i++)
39 {
40 // FIXME: There may be a neater way to set this bool
41 if (i == 0)
42 ranCommands = true;
43
44 if (error)
45 {
46 compLogMessage ("startup", CompLogLevelError, "An error occurred, doing nothing.");
47 return;
48 }
49 // else
50 // Run the commands.
51 // If first time in this session, run all commands except with option 2
52 if (firstSession && commands[i].interval != 2)
53 {
54 screen->runCommand (commands[i].command);
55 continue;
56 }
57 // If we've already run compiz at least once in this session, run all commands with option 1 (Every)
58 if (firstRun && commands[i].interval == 1)
59 {
60 screen->runCommand (commands[i].command);
61 continue;
62 }
63 // Hopefully, these will be all of the commands with option 2 :-P
64 if (!firstSession && !alreadyRunning && commands[i].interval == 2)
65 screen->runCommand (commands[i].command);
66 }
67
68 return;
69}
70
71void
72StartupScreen::UpdateStatus()
73{
74
75 // We're only interested in the dbus ID
76 CompString s(dbus_env_var);
77 size_t idx = s.find("guid=");
78 CompString dbus_id = s.substr(idx+5) + "\n";
79
80
81 std::fstream lock;
82 int nCompPid = getpid();
83 CompString compLockFile = lockdir + "complock" + dsp;
84 CompString xLockFile = lockdir + "xlock" + dsp;
85
86 lock.open(xLockFile.c_str (), std::ios::in);
87 if (!lock)
88 {
89 compLogMessage ("startup", CompLogLevelWarn, "Could not open %s for reading: %s", xLockFile.c_str (), strerror(errno));
90 compLogMessage ("startup", CompLogLevelWarn, "Perhaps this is the first time using this plugin?");
91 }
92 else
93 {
94 int nCompLock = 0;
95 std::stringstream xstrm;
96 xstrm << lock.rdbuf ();
97 lock.close ();
98 lock.open(compLockFile.c_str (), std::ios::in);
99 if (!lock)
100 {
101 compLogMessage ("startup", CompLogLevelWarn, "Could not open %s for reading: %s", compLockFile.c_str (), strerror(errno));
102 compLogMessage ("startup", CompLogLevelWarn, "Perhaps this is the first time using this plugin?");
103 }
104 else
105 {
106 lock >> nCompLock;
107 lock.close ();
108 if (xstrm.str () == dbus_id)
109 {
110 // Compiz has already been run in this X session
111 if (nCompLock == nCompPid)
112 {
113 // Control is reaching this path but compiz is already running
114 // Plugins are most likely being reloaded
115 if (!firstRun)
116 alreadyRunning = true;
117 return;
118 }
119 else
120 {
121 lock.open(compLockFile.c_str (), std::ios::out);
122 if (!lock)
123 compLogMessage ("startup", CompLogLevelWarn, "Couldn't open %s for writing: %s", compLockFile.c_str (), strerror(errno));
124 else
125 {
126 // Compiz has just been started. Save it's PID
127 if (!firstSession)
128 firstRun = true;
129 lock << nCompPid;
130 lock.close ();
131 return;
132 }
133 }
134 }
135 }
136 }
137 mkdir_p(lockdir);
138 lock.open (xLockFile.c_str (), std::ios::out);
139 if (!lock)
140 compLogMessage ("startup", CompLogLevelWarn, "Could not open %s for writing: %s", xLockFile.c_str (), strerror(errno));
141 else
142 {
143 // First time compiz has been run in this X session
144 firstSession = true;
145 lock << dbus_id;
146 lock.close();
147 }
148 lock.open(compLockFile.c_str (), std::ios::out);
149 if (!lock)
150 {
151 compLogMessage ("startup", CompLogLevelWarn, "Could not open %s for writing: %s", compLockFile.c_str (), strerror(errno));
152 }
153 else
154 {
155 // Save the PID
156 if(firstSession)
157 lock << nCompPid;
158 lock.close ();
159 return;
160 }
161
162 return;
163}
164
165bool
166StartupWindow::damageRect (bool initial,
167 const CompRect &rect)
168{
169 STARTUP_SCREEN (screen);
170
171 if (!ss->ranCommands)
172 ss->RunCommands();
173 else
174 cWindow->damageRectSetEnabled (this, false);
175
176 return cWindow->damageRect (initial, rect);
177}
178
179void
180StartupScreen::updateOptions ()
181{
182
183#define GET_OPTION(opt) CompOption::Value::Vector c##opt = optionGet##opt ();
184 GET_OPTION (PostStartupCommand);
185 GET_OPTION (PostStartupInterval);
186#undef GET_OPTION
187
188 if (cPostStartupCommand.size () != cPostStartupInterval.size ())
189 {
190 compLogMessage ("startup", CompLogLevelWarn, "Malformed option");
191 return;
192 }
193
194 commands.clear ();
195
196 for (unsigned int i = 0; i < cPostStartupCommand.size (); i++, numCommands++)
197 {
198 commands.push_back (StartupCommand ());
199 commands[i].command = cPostStartupCommand[i].s ();
200 commands[i].interval = cPostStartupInterval[i].i ();
201 }
202
203 UpdateStatus ();
204
205 return;
206}
207
208void
209StartupScreen::optionChanged (CompOption *opt, Options num)
210{
211 updateOptions ();
212}
213
214StartupScreen::StartupScreen (CompScreen *screen) :
215 PluginClassHandler <StartupScreen, CompScreen> (screen),
216 cScreen (CompositeScreen::get (screen)),
217 commands ()
218{
219 optionSetPostStartupCommandNotify (boost::bind (&StartupScreen::
220 optionChanged, this, _1, _2));
221
222 ranCommands = firstRun = firstSession = alreadyRunning = error = false;
223
224 numCommands = 0;
225
226#define GET_ENV_VAR(ourvar, envvar, error) \
227 ourvar = getenv(#envvar); \
228 if (ourvar == NULL) \
229 { \
230 compLogMessage ("startup", CompLogLevelError, "Environment variable " #envvar " is not set"); \
231 error = true; \
232 return; \
233}
234
235 GET_ENV_VAR (dbus_env_var, DBUS_SESSION_BUS_ADDRESS, error)
236 GET_ENV_VAR (dsp, DISPLAY, error)
237 GET_ENV_VAR (home, HOME, error)
238 #undef GET_ENV_VAR
239
240 // We may be at risk of modifying the actual DISPLAY env var here
241 dsp[2] = 0;
242 // though tests have shown it doesn't happen
243
244 lockdir = "/.compiz/locks/startup/";
245 lockdir.insert (0,home);
246}
247
248StartupWindow::StartupWindow (CompWindow *window) :
249 PluginClassHandler <StartupWindow, CompWindow> (window),
250 cWindow (CompositeWindow::get (window))
251{
252 CompositeWindowInterface::setHandler (cWindow);
253}
254
255StartupScreen::~StartupScreen ()
256{
257}
258
259StartupWindow::~StartupWindow ()
260{
261}
262
263bool
264StartupPluginVTable::init ()
265{
266 if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) ||
267 !CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI))
268 {
269 compLogMessage ("startup", CompLogLevelError, "Unable to verify if core and composite are present\n");
270 return false;
271 }
272
273 return true;
274}
0275
=== added file 'plugins/startup/src/startup.h'
--- plugins/startup/src/startup.h 1970-01-01 00:00:00 +0000
+++ plugins/startup/src/startup.h 2013-01-31 19:35:25 +0000
@@ -0,0 +1,75 @@
1#include <fstream>
2#include <errno.h>
3#include <sstream>
4#include <sys/stat.h>
5#include <core/core.h>
6#include <composite/composite.h>
7
8#include "startup_options.h"
9
10class StartupCommand
11{
12 public:
13
14 CompString command;
15 int interval;
16};
17
18typedef std::vector<StartupCommand> StartupCommands;
19
20class StartupScreen :
21 public PluginClassHandler <StartupScreen, CompScreen>,
22 public StartupOptions
23{
24 public:
25
26 StartupScreen (CompScreen *);
27 ~StartupScreen ();
28
29 CompositeScreen *cScreen;
30
31 bool ranCommands, firstRun, firstSession, alreadyRunning, error;
32
33 char *dbus_env_var, *dsp, *home;
34
35 CompString lockdir;
36
37 StartupCommands commands;
38
39 int numCommands;
40
41 void updateOptions ();
42
43 void UpdateStatus ();
44
45 void RunCommands ();
46
47 void optionChanged (CompOption*, Options);
48};
49
50class StartupWindow :
51 public PluginClassHandler <StartupWindow, CompWindow>,
52 public CompositeWindowInterface
53{
54 public:
55
56 StartupWindow (CompWindow *);
57 ~StartupWindow ();
58
59 CompWindow *window;
60 CompositeWindow *cWindow;
61
62 bool
63 damageRect (bool, const CompRect&);
64};
65
66#define STARTUP_SCREEN(s) \
67 StartupScreen *ss = StartupScreen::get (s);
68
69class StartupPluginVTable :
70 public CompPlugin::VTableForScreenAndWindow <StartupScreen, StartupWindow>
71{
72 public:
73
74 bool init ();
75};
076
=== added file 'plugins/startup/startup.xml.in'
--- plugins/startup/startup.xml.in 1970-01-01 00:00:00 +0000
+++ plugins/startup/startup.xml.in 2013-01-31 19:35:25 +0000
@@ -0,0 +1,45 @@
1<?xml version="1.0"?>
2<compiz>
3 <plugin name="startup" useBcop="true">
4 <_short>Startup</_short>
5 <_long>Run commands after compiz is properly loaded</_long>
6 <category>Utility</category>
7 <deps>
8 <requirement>
9 <plugin>composite</plugin>
10 </requirement>
11 <relation type="after">
12 <plugin>composite</plugin>
13 </relation>
14 </deps>
15 <options>
16 <subgroup>
17 <option name="post_startup_command" type="list">
18 <_short>Command</_short>
19 <_long>Command to run</_long>
20 <type>string</type>
21 </option>
22 <option name="post_startup_interval" type="list">
23 <_short>Interval</_short>
24 <_long>Interval the command will be run per X session. First Time: First time Compiz is started. Every Time: Every time Compiz starts. After First: Every time except the first time.</_long>
25 <type>int</type>
26 <min>0</min>
27 <max>2</max>
28 <desc>
29 <value>0</value>
30 <_name>First Time</_name>
31 </desc>
32 <desc>
33 <value>1</value>
34 <_name>Every Time</_name>
35 </desc>
36 <desc>
37 <value>2</value>
38 <_name>After First</_name>
39 </desc>
40 </option>
41 </subgroup>
42 </options>
43 </plugin>
44</compiz>
45

Subscribers

People subscribed via source and target branches