aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Remember.cc75
-rw-r--r--src/Remember.hh7
2 files changed, 79 insertions, 3 deletions
diff --git a/src/Remember.cc b/src/Remember.cc
index 0b4b248..883d00e 100644
--- a/src/Remember.cc
+++ b/src/Remember.cc
@@ -21,7 +21,7 @@
21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22// DEALINGS IN THE SOFTWARE. 22// DEALINGS IN THE SOFTWARE.
23 23
24// $Id: Remember.cc,v 1.26 2003/07/04 14:06:20 rathnor Exp $ 24// $Id: Remember.cc,v 1.27 2003/07/10 13:23:09 rathnor Exp $
25 25
26#include "Remember.hh" 26#include "Remember.hh"
27#include "ClientPattern.hh" 27#include "ClientPattern.hh"
@@ -32,6 +32,7 @@
32#include "FbMenu.hh" 32#include "FbMenu.hh"
33#include "MenuItem.hh" 33#include "MenuItem.hh"
34#include "App.hh" 34#include "App.hh"
35#include "FbCommands.hh"
35 36
36#include <X11/Xlib.h> 37#include <X11/Xlib.h>
37 38
@@ -127,8 +128,63 @@ FbTk::Menu *createRememberMenu(Remember &remember, FluxboxWindow &win) {
127 return menu; 128 return menu;
128}; 129};
129 130
131// offset is the offset in the string that we start looking from
132// return true if all ok, false on error
133bool handleStartupItem(string line, int offset) {
134 int next = 0;
135 string str;
136 int screen = 0;
137
138 // accept some options, for now only "screen=NN"
139 // these option are given in parentheses before the command
140 next = FbTk::StringUtil::getStringBetween(str,
141 line.c_str() + offset,
142 '(', ')');
143 if (next > 0) {
144 // there are some options
145 string option;
146 int pos = str.find('=');
147 bool error = false;
148 if (pos > 0) {
149 option = str.substr(0, pos);
150 if (option == "screen") {
151 istringstream iss(str.c_str() + pos + 1);
152 iss >> screen;
153 } else {
154 error = true;
155 }
156 } else {
157 error = true;
158 }
159 if (error) {
160 cerr<<"Error parsing startup options."<<endl;
161 return false;
162 }
163 } else {
164 next = 0;
165 }
166
167 next = FbTk::StringUtil::getStringBetween(str,
168 line.c_str() + offset + next,
169 '{', '}');
170
171 if (next <= 0) {
172 cerr<<"Error parsing [startup] at column "<<offset<<" - expecting {command}."<<endl;
173 return false;
174 } else {
175 FbCommands::ExecuteCmd *tmp_exec_cmd = new FbCommands::ExecuteCmd(str, screen);
176#ifdef DEBUG
177 cerr<<"Executing startup command '"<<str<<"' on screen "<<screen<<endl;
178#endif // DEBUG
179 tmp_exec_cmd->execute();
180 delete tmp_exec_cmd;
181 return true;
182 }
183};
184
130}; // end anonymous namespace 185}; // end anonymous namespace
131 186
187
132Application::Application(bool grouped) 188Application::Application(bool grouped)
133 : is_grouped(grouped), 189 : is_grouped(grouped),
134 group(0) 190 group(0)
@@ -350,6 +406,12 @@ void Remember::load() {
350 } else { 406 } else {
351 grouped_pats.push_back(pat); 407 grouped_pats.push_back(pat);
352 } 408 }
409 } else if (pos > 0 && key == "startup") {
410 if (!handleStartupItem(line, pos)) {
411 cerr<<"Error reading apps file at line "<<row<<"."<<endl;
412 }
413 // save the item even if it was bad (aren't we nice)
414 m_startups.push_back(line.substr(pos));
353 } else if (pos > 0 && key == "group") { 415 } else if (pos > 0 && key == "group") {
354 in_group = true; 416 in_group = true;
355 } else if (in_group) { 417 } else if (in_group) {
@@ -389,6 +451,14 @@ void Remember::save() {
389 string apps_string; 451 string apps_string;
390 Fluxbox::instance()->getDefaultDataFilename("apps", apps_string); 452 Fluxbox::instance()->getDefaultDataFilename("apps", apps_string);
391 ofstream apps_file(apps_string.c_str()); 453 ofstream apps_file(apps_string.c_str());
454
455 // first of all we output all the startup commands
456 Startups::iterator sit = m_startups.begin();
457 Startups::iterator sit_end = m_startups.end();
458 for (; sit != sit_end; ++sit) {
459 apps_file<<"[startup] "<<(*sit)<<endl;
460 }
461
392 Patterns::iterator it = m_pats.begin(); 462 Patterns::iterator it = m_pats.begin();
393 Patterns::iterator it_end = m_pats.end(); 463 Patterns::iterator it_end = m_pats.end();
394 464
@@ -400,12 +470,13 @@ void Remember::save() {
400 // if already processed 470 // if already processed
401 if (grouped_apps.find(&a) != grouped_apps.end()) 471 if (grouped_apps.find(&a) != grouped_apps.end())
402 continue; 472 continue;
473 grouped_apps.insert(&a);
403 // otherwise output this whole group 474 // otherwise output this whole group
404 apps_file << "[group]" << endl; 475 apps_file << "[group]" << endl;
405 Patterns::iterator git = m_pats.begin(); 476 Patterns::iterator git = m_pats.begin();
406 Patterns::iterator git_end = m_pats.end(); 477 Patterns::iterator git_end = m_pats.end();
407 for (; git != git_end; git++) { 478 for (; git != git_end; git++) {
408 if (git->second->group == a.group) { 479 if (git->second == &a) {
409 apps_file << " [app]"<<git->first->toString()<<endl; 480 apps_file << " [app]"<<git->first->toString()<<endl;
410 } 481 }
411 } 482 }
diff --git a/src/Remember.hh b/src/Remember.hh
index c687137..4520c23 100644
--- a/src/Remember.hh
+++ b/src/Remember.hh
@@ -21,7 +21,7 @@
21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22// DEALINGS IN THE SOFTWARE. 22// DEALINGS IN THE SOFTWARE.
23 23
24// $Id: Remember.hh,v 1.10 2003/07/04 14:06:20 rathnor Exp $ 24// $Id: Remember.hh,v 1.11 2003/07/10 13:23:09 rathnor Exp $
25 25
26/* Based on the original "Remember patch" by Xavier Brouckaert */ 26/* Based on the original "Remember patch" by Xavier Brouckaert */
27 27
@@ -148,6 +148,9 @@ public:
148 // particularly useful to update counters etc on windowclose 148 // particularly useful to update counters etc on windowclose
149 typedef std::map<WinClient *, Application *> Clients; 149 typedef std::map<WinClient *, Application *> Clients;
150 150
151 // we have to remember any startups we did so that they are saved again
152 typedef std::list<std::string> Startups;
153
151 Remember(); 154 Remember();
152 ~Remember(); 155 ~Remember();
153 156
@@ -196,6 +199,8 @@ private:
196 Patterns m_pats; 199 Patterns m_pats;
197 Clients m_clients; 200 Clients m_clients;
198 201
202 Startups m_startups;
203
199}; 204};
200 205
201#endif // REMEMBER_HH 206#endif // REMEMBER_HH