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
1=== modified file 'debian/compiz-plugins.install'
2--- debian/compiz-plugins.install 2013-01-10 10:53:57 +0000
3+++ debian/compiz-plugins.install 2013-01-31 19:35:25 +0000
4@@ -39,6 +39,7 @@
5 debian/tmp/usr/share/compiz/showmouse
6 debian/tmp/usr/*/compiz/*splash.*
7 debian/tmp/usr/share/compiz/splash
8+debian/tmp/usr/*/compiz/*startup.*
9 debian/tmp/usr/*/compiz/*showrepaint.*
10 debian/tmp/usr/*/compiz/*switcher.*
11 debian/tmp/usr/*/compiz/*td.*
12
13=== added directory 'plugins/startup'
14=== added file 'plugins/startup/CMakeLists.txt'
15--- plugins/startup/CMakeLists.txt 1970-01-01 00:00:00 +0000
16+++ plugins/startup/CMakeLists.txt 2013-01-31 19:35:25 +0000
17@@ -0,0 +1,5 @@
18+find_package (Compiz REQUIRED)
19+
20+include (CompizPlugin)
21+
22+compiz_plugin (startup PLUGINDEPS composite)
23
24=== added directory 'plugins/startup/src'
25=== added file 'plugins/startup/src/startup.cpp'
26--- plugins/startup/src/startup.cpp 1970-01-01 00:00:00 +0000
27+++ plugins/startup/src/startup.cpp 2013-01-31 19:35:25 +0000
28@@ -0,0 +1,274 @@
29+#include "startup.h"
30+
31+
32+COMPIZ_PLUGIN_20090315 (startup, StartupPluginVTable);
33+
34+// mkdir_p: Creates a directory making parent directories as needed.
35+// (same as mkdir -p)
36+
37+void
38+mkdir_p(CompString &pathname)
39+{
40+ if (mkdir(pathname.c_str(), 0777) < 0)
41+ {
42+ // If we couldn't make the whole directory because of ENOENT (a
43+ // parent directory doesn't exist), then try recursively to make
44+ // the immediate parent directory.
45+ if (errno == ENOENT)
46+ {
47+ size_t slash = pathname.rfind('/');
48+ if (slash != CompString::npos)
49+ {
50+ CompString prefix = pathname.substr(0, slash);
51+ mkdir_p(prefix);
52+ mkdir(pathname.c_str(), 0777);
53+ }
54+ }
55+ }
56+}
57+
58+void
59+StartupScreen::RunCommands()
60+{
61+ updateOptions();
62+
63+ if (numCommands < 1);
64+ ranCommands = true;
65+
66+ for (int i = 0; i < numCommands; i++)
67+ {
68+ // FIXME: There may be a neater way to set this bool
69+ if (i == 0)
70+ ranCommands = true;
71+
72+ if (error)
73+ {
74+ compLogMessage ("startup", CompLogLevelError, "An error occurred, doing nothing.");
75+ return;
76+ }
77+ // else
78+ // Run the commands.
79+ // If first time in this session, run all commands except with option 2
80+ if (firstSession && commands[i].interval != 2)
81+ {
82+ screen->runCommand (commands[i].command);
83+ continue;
84+ }
85+ // If we've already run compiz at least once in this session, run all commands with option 1 (Every)
86+ if (firstRun && commands[i].interval == 1)
87+ {
88+ screen->runCommand (commands[i].command);
89+ continue;
90+ }
91+ // Hopefully, these will be all of the commands with option 2 :-P
92+ if (!firstSession && !alreadyRunning && commands[i].interval == 2)
93+ screen->runCommand (commands[i].command);
94+ }
95+
96+ return;
97+}
98+
99+void
100+StartupScreen::UpdateStatus()
101+{
102+
103+ // We're only interested in the dbus ID
104+ CompString s(dbus_env_var);
105+ size_t idx = s.find("guid=");
106+ CompString dbus_id = s.substr(idx+5) + "\n";
107+
108+
109+ std::fstream lock;
110+ int nCompPid = getpid();
111+ CompString compLockFile = lockdir + "complock" + dsp;
112+ CompString xLockFile = lockdir + "xlock" + dsp;
113+
114+ lock.open(xLockFile.c_str (), std::ios::in);
115+ if (!lock)
116+ {
117+ compLogMessage ("startup", CompLogLevelWarn, "Could not open %s for reading: %s", xLockFile.c_str (), strerror(errno));
118+ compLogMessage ("startup", CompLogLevelWarn, "Perhaps this is the first time using this plugin?");
119+ }
120+ else
121+ {
122+ int nCompLock = 0;
123+ std::stringstream xstrm;
124+ xstrm << lock.rdbuf ();
125+ lock.close ();
126+ lock.open(compLockFile.c_str (), std::ios::in);
127+ if (!lock)
128+ {
129+ compLogMessage ("startup", CompLogLevelWarn, "Could not open %s for reading: %s", compLockFile.c_str (), strerror(errno));
130+ compLogMessage ("startup", CompLogLevelWarn, "Perhaps this is the first time using this plugin?");
131+ }
132+ else
133+ {
134+ lock >> nCompLock;
135+ lock.close ();
136+ if (xstrm.str () == dbus_id)
137+ {
138+ // Compiz has already been run in this X session
139+ if (nCompLock == nCompPid)
140+ {
141+ // Control is reaching this path but compiz is already running
142+ // Plugins are most likely being reloaded
143+ if (!firstRun)
144+ alreadyRunning = true;
145+ return;
146+ }
147+ else
148+ {
149+ lock.open(compLockFile.c_str (), std::ios::out);
150+ if (!lock)
151+ compLogMessage ("startup", CompLogLevelWarn, "Couldn't open %s for writing: %s", compLockFile.c_str (), strerror(errno));
152+ else
153+ {
154+ // Compiz has just been started. Save it's PID
155+ if (!firstSession)
156+ firstRun = true;
157+ lock << nCompPid;
158+ lock.close ();
159+ return;
160+ }
161+ }
162+ }
163+ }
164+ }
165+ mkdir_p(lockdir);
166+ lock.open (xLockFile.c_str (), std::ios::out);
167+ if (!lock)
168+ compLogMessage ("startup", CompLogLevelWarn, "Could not open %s for writing: %s", xLockFile.c_str (), strerror(errno));
169+ else
170+ {
171+ // First time compiz has been run in this X session
172+ firstSession = true;
173+ lock << dbus_id;
174+ lock.close();
175+ }
176+ lock.open(compLockFile.c_str (), std::ios::out);
177+ if (!lock)
178+ {
179+ compLogMessage ("startup", CompLogLevelWarn, "Could not open %s for writing: %s", compLockFile.c_str (), strerror(errno));
180+ }
181+ else
182+ {
183+ // Save the PID
184+ if(firstSession)
185+ lock << nCompPid;
186+ lock.close ();
187+ return;
188+ }
189+
190+ return;
191+}
192+
193+bool
194+StartupWindow::damageRect (bool initial,
195+ const CompRect &rect)
196+{
197+ STARTUP_SCREEN (screen);
198+
199+ if (!ss->ranCommands)
200+ ss->RunCommands();
201+ else
202+ cWindow->damageRectSetEnabled (this, false);
203+
204+ return cWindow->damageRect (initial, rect);
205+}
206+
207+void
208+StartupScreen::updateOptions ()
209+{
210+
211+#define GET_OPTION(opt) CompOption::Value::Vector c##opt = optionGet##opt ();
212+ GET_OPTION (PostStartupCommand);
213+ GET_OPTION (PostStartupInterval);
214+#undef GET_OPTION
215+
216+ if (cPostStartupCommand.size () != cPostStartupInterval.size ())
217+ {
218+ compLogMessage ("startup", CompLogLevelWarn, "Malformed option");
219+ return;
220+ }
221+
222+ commands.clear ();
223+
224+ for (unsigned int i = 0; i < cPostStartupCommand.size (); i++, numCommands++)
225+ {
226+ commands.push_back (StartupCommand ());
227+ commands[i].command = cPostStartupCommand[i].s ();
228+ commands[i].interval = cPostStartupInterval[i].i ();
229+ }
230+
231+ UpdateStatus ();
232+
233+ return;
234+}
235+
236+void
237+StartupScreen::optionChanged (CompOption *opt, Options num)
238+{
239+ updateOptions ();
240+}
241+
242+StartupScreen::StartupScreen (CompScreen *screen) :
243+ PluginClassHandler <StartupScreen, CompScreen> (screen),
244+ cScreen (CompositeScreen::get (screen)),
245+ commands ()
246+{
247+ optionSetPostStartupCommandNotify (boost::bind (&StartupScreen::
248+ optionChanged, this, _1, _2));
249+
250+ ranCommands = firstRun = firstSession = alreadyRunning = error = false;
251+
252+ numCommands = 0;
253+
254+#define GET_ENV_VAR(ourvar, envvar, error) \
255+ ourvar = getenv(#envvar); \
256+ if (ourvar == NULL) \
257+ { \
258+ compLogMessage ("startup", CompLogLevelError, "Environment variable " #envvar " is not set"); \
259+ error = true; \
260+ return; \
261+}
262+
263+ GET_ENV_VAR (dbus_env_var, DBUS_SESSION_BUS_ADDRESS, error)
264+ GET_ENV_VAR (dsp, DISPLAY, error)
265+ GET_ENV_VAR (home, HOME, error)
266+ #undef GET_ENV_VAR
267+
268+ // We may be at risk of modifying the actual DISPLAY env var here
269+ dsp[2] = 0;
270+ // though tests have shown it doesn't happen
271+
272+ lockdir = "/.compiz/locks/startup/";
273+ lockdir.insert (0,home);
274+}
275+
276+StartupWindow::StartupWindow (CompWindow *window) :
277+ PluginClassHandler <StartupWindow, CompWindow> (window),
278+ cWindow (CompositeWindow::get (window))
279+{
280+ CompositeWindowInterface::setHandler (cWindow);
281+}
282+
283+StartupScreen::~StartupScreen ()
284+{
285+}
286+
287+StartupWindow::~StartupWindow ()
288+{
289+}
290+
291+bool
292+StartupPluginVTable::init ()
293+{
294+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) ||
295+ !CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI))
296+ {
297+ compLogMessage ("startup", CompLogLevelError, "Unable to verify if core and composite are present\n");
298+ return false;
299+ }
300+
301+ return true;
302+}
303
304=== added file 'plugins/startup/src/startup.h'
305--- plugins/startup/src/startup.h 1970-01-01 00:00:00 +0000
306+++ plugins/startup/src/startup.h 2013-01-31 19:35:25 +0000
307@@ -0,0 +1,75 @@
308+#include <fstream>
309+#include <errno.h>
310+#include <sstream>
311+#include <sys/stat.h>
312+#include <core/core.h>
313+#include <composite/composite.h>
314+
315+#include "startup_options.h"
316+
317+class StartupCommand
318+{
319+ public:
320+
321+ CompString command;
322+ int interval;
323+};
324+
325+typedef std::vector<StartupCommand> StartupCommands;
326+
327+class StartupScreen :
328+ public PluginClassHandler <StartupScreen, CompScreen>,
329+ public StartupOptions
330+{
331+ public:
332+
333+ StartupScreen (CompScreen *);
334+ ~StartupScreen ();
335+
336+ CompositeScreen *cScreen;
337+
338+ bool ranCommands, firstRun, firstSession, alreadyRunning, error;
339+
340+ char *dbus_env_var, *dsp, *home;
341+
342+ CompString lockdir;
343+
344+ StartupCommands commands;
345+
346+ int numCommands;
347+
348+ void updateOptions ();
349+
350+ void UpdateStatus ();
351+
352+ void RunCommands ();
353+
354+ void optionChanged (CompOption*, Options);
355+};
356+
357+class StartupWindow :
358+ public PluginClassHandler <StartupWindow, CompWindow>,
359+ public CompositeWindowInterface
360+{
361+ public:
362+
363+ StartupWindow (CompWindow *);
364+ ~StartupWindow ();
365+
366+ CompWindow *window;
367+ CompositeWindow *cWindow;
368+
369+ bool
370+ damageRect (bool, const CompRect&);
371+};
372+
373+#define STARTUP_SCREEN(s) \
374+ StartupScreen *ss = StartupScreen::get (s);
375+
376+class StartupPluginVTable :
377+ public CompPlugin::VTableForScreenAndWindow <StartupScreen, StartupWindow>
378+{
379+ public:
380+
381+ bool init ();
382+};
383
384=== added file 'plugins/startup/startup.xml.in'
385--- plugins/startup/startup.xml.in 1970-01-01 00:00:00 +0000
386+++ plugins/startup/startup.xml.in 2013-01-31 19:35:25 +0000
387@@ -0,0 +1,45 @@
388+<?xml version="1.0"?>
389+<compiz>
390+ <plugin name="startup" useBcop="true">
391+ <_short>Startup</_short>
392+ <_long>Run commands after compiz is properly loaded</_long>
393+ <category>Utility</category>
394+ <deps>
395+ <requirement>
396+ <plugin>composite</plugin>
397+ </requirement>
398+ <relation type="after">
399+ <plugin>composite</plugin>
400+ </relation>
401+ </deps>
402+ <options>
403+ <subgroup>
404+ <option name="post_startup_command" type="list">
405+ <_short>Command</_short>
406+ <_long>Command to run</_long>
407+ <type>string</type>
408+ </option>
409+ <option name="post_startup_interval" type="list">
410+ <_short>Interval</_short>
411+ <_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>
412+ <type>int</type>
413+ <min>0</min>
414+ <max>2</max>
415+ <desc>
416+ <value>0</value>
417+ <_name>First Time</_name>
418+ </desc>
419+ <desc>
420+ <value>1</value>
421+ <_name>Every Time</_name>
422+ </desc>
423+ <desc>
424+ <value>2</value>
425+ <_name>After First</_name>
426+ </desc>
427+ </option>
428+ </subgroup>
429+ </options>
430+ </plugin>
431+</compiz>
432+

Subscribers

People subscribed via source and target branches