aboutsummaryrefslogtreecommitdiff
path: root/src/Remember.cc
diff options
context:
space:
mode:
authorrathnor <rathnor>2003-07-04 01:03:41 (GMT)
committerrathnor <rathnor>2003-07-04 01:03:41 (GMT)
commit3144086eef171f6c402182f23bfc80a101e71fa2 (patch)
tree0df61dbcb4a7ce44fd90369b031e5a39037807c0 /src/Remember.cc
parent672ac023526d61af2e102a3a27b67eeedb2c4f10 (diff)
downloadfluxbox_pavel-3144086eef171f6c402182f23bfc80a101e71fa2.zip
fluxbox_pavel-3144086eef171f6c402182f23bfc80a101e71fa2.tar.bz2
support in remember for specifying groups.
Also split atomhandler::setupWindow
Diffstat (limited to 'src/Remember.cc')
-rw-r--r--src/Remember.cc111
1 files changed, 96 insertions, 15 deletions
diff --git a/src/Remember.cc b/src/Remember.cc
index a31843b..97d1e35 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.24 2003/06/12 15:12:19 rathnor Exp $ 24// $Id: Remember.cc,v 1.25 2003/07/04 01:03:40 rathnor Exp $
25 25
26#include "Remember.hh" 26#include "Remember.hh"
27#include "ClientPattern.hh" 27#include "ClientPattern.hh"
@@ -46,6 +46,7 @@
46#include <fstream> 46#include <fstream>
47#include <string> 47#include <string>
48#include <memory> 48#include <memory>
49#include <set>
49 50
50using namespace std; 51using namespace std;
51 52
@@ -128,7 +129,10 @@ FbTk::Menu *createRememberMenu(Remember &remember, FluxboxWindow &win) {
128 129
129}; // end anonymous namespace 130}; // end anonymous namespace
130 131
131Application::Application() { 132Application::Application(bool grouped)
133 : is_grouped(grouped),
134 group(0)
135{
132 workspace_remember = 136 workspace_remember =
133 dimensions_remember = 137 dimensions_remember =
134 position_remember = 138 position_remember =
@@ -146,6 +150,7 @@ Application::Application() {
146 ************/ 150 ************/
147 151
148Remember::Remember() { 152Remember::Remember() {
153 enableUpdate();
149 load(); 154 load();
150} 155}
151 156
@@ -155,12 +160,19 @@ Remember::~Remember() {
155 // the patterns free the "Application"s 160 // the patterns free the "Application"s
156 // the client mapping shouldn't need cleaning 161 // the client mapping shouldn't need cleaning
157 Patterns::iterator it; 162 Patterns::iterator it;
163 std::set<Application *> all_apps; // no duplicates
158 while (!m_pats.empty()) { 164 while (!m_pats.empty()) {
159 it = m_pats.begin(); 165 it = m_pats.begin();
160 delete it->first; // ClientPattern 166 delete it->first; // ClientPattern
161 delete it->second; // Application 167 all_apps.insert(it->second); // Application, not necessarily unique
162 m_pats.erase(it); 168 m_pats.erase(it);
163 } 169 }
170
171 std::set<Application *>::iterator ait = all_apps.begin(); // no duplicates
172 while (ait != all_apps.end()) {
173 delete (*ait);
174 ++ait;
175 }
164} 176}
165 177
166Application* Remember::find(WinClient &winclient) { 178Application* Remember::find(WinClient &winclient) {
@@ -184,7 +196,7 @@ Application* Remember::find(WinClient &winclient) {
184 196
185Application * Remember::add(WinClient &winclient) { 197Application * Remember::add(WinClient &winclient) {
186 ClientPattern *p = new ClientPattern(); 198 ClientPattern *p = new ClientPattern();
187 Application *app = new Application(); 199 Application *app = new Application(false);
188 // by default, we match against the WMClass of a window. 200 // by default, we match against the WMClass of a window.
189 p->addTerm(p->getProperty(ClientPattern::NAME, winclient), ClientPattern::NAME); 201 p->addTerm(p->getProperty(ClientPattern::NAME, winclient), ClientPattern::NAME);
190 m_clients[&winclient] = app; 202 m_clients[&winclient] = app;
@@ -193,11 +205,16 @@ Application * Remember::add(WinClient &winclient) {
193 return app; 205 return app;
194} 206}
195 207
196int Remember::parseApp(ifstream &file, Application &app) { 208int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
197 string line; 209 string line;
198 int row = 0; 210 int row = 0;
199 while (! file.eof()) { 211 while (! file.eof()) {
200 if (getline(file, line)) { 212 if (first_line || getline(file, line)) {
213 if (first_line) {
214 line = *first_line;
215 first_line = 0;
216 }
217
201 row++; 218 row++;
202 if (line[0] != '#') { //the line is commented 219 if (line[0] != '#') { //the line is commented
203 int parse_pos = 0, err = 0; 220 int parse_pos = 0, err = 0;
@@ -307,6 +324,8 @@ void Remember::load() {
307 if (!apps_file.eof()) { 324 if (!apps_file.eof()) {
308 string line; 325 string line;
309 int row = 0; 326 int row = 0;
327 bool in_group = false;
328 std::list<ClientPattern *> grouped_pats;
310 while (getline(apps_file, line) && ! apps_file.eof()) { 329 while (getline(apps_file, line) && ! apps_file.eof()) {
311 row++; 330 row++;
312 if (line[0] == '#') 331 if (line[0] == '#')
@@ -319,14 +338,36 @@ void Remember::load() {
319 338
320 if (pos > 0 && key == "app") { 339 if (pos > 0 && key == "app") {
321 ClientPattern *pat = new ClientPattern(line.c_str() + pos); 340 ClientPattern *pat = new ClientPattern(line.c_str() + pos);
322 if ((err = pat->error()) == 0) { 341 if (!in_group) {
323 Application *app = new Application(); 342 if ((err = pat->error()) == 0) {
324 m_pats.push_back(make_pair(pat, app)); 343 Application *app = new Application(false);
325 row += parseApp(apps_file, *app); 344 m_pats.push_back(make_pair(pat, app));
345 row += parseApp(apps_file, *app);
346 } else {
347 cerr<<"Error reading apps file at line "<<row<<", column "<<(err+pos)<<"."<<endl;
348 delete pat; // since it didn't work
349 }
326 } else { 350 } else {
327 cerr<<"Error reading apps file at line "<<row<<", column "<<(err+pos)<<"."<<endl; 351 grouped_pats.push_back(pat);
328 delete pat; // since it didn't work 352 }
353 } else if (pos > 0 && key == "group") {
354 in_group = true;
355 } else if (in_group) {
356 // otherwise assume that it is the start of the attributes
357 Application *app = new Application(true);
358 while (!grouped_pats.empty()) {
359 // associate all the patterns with this app
360 m_pats.push_back(make_pair(grouped_pats.front(), app));
361 grouped_pats.pop_front();
362 }
363
364 // we hit end... probably don't have attribs for the group
365 // so finish it off with an empty application
366 // otherwise parse the app
367 if (!(pos>0 && key == "end")) {
368 row += parseApp(apps_file, *app, &line);
329 } 369 }
370 in_group = false;
330 } else 371 } else
331 cerr<<"Error in apps file on line "<<row<<"."<<endl; 372 cerr<<"Error in apps file on line "<<row<<"."<<endl;
332 373
@@ -350,9 +391,27 @@ void Remember::save() {
350 ofstream apps_file(apps_string.c_str()); 391 ofstream apps_file(apps_string.c_str());
351 Patterns::iterator it = m_pats.begin(); 392 Patterns::iterator it = m_pats.begin();
352 Patterns::iterator it_end = m_pats.end(); 393 Patterns::iterator it_end = m_pats.end();
394
395 std::set<Application *> grouped_apps; // no duplicates
396
353 for (; it != it_end; ++it) { 397 for (; it != it_end; ++it) {
354 apps_file << "[app]"<<it->first->toString()<<endl;
355 Application &a = *it->second; 398 Application &a = *it->second;
399 if (a.is_grouped) {
400 // if already processed
401 if (grouped_apps.find(&a) != grouped_apps.end())
402 continue;
403 // otherwise output this whole group
404 apps_file << "[group]" << endl;
405 Patterns::iterator git = m_pats.begin();
406 Patterns::iterator git_end = m_pats.end();
407 for (; git != git_end; git++) {
408 if (git->second->group == a.group) {
409 apps_file << " [app]"<<git->first->toString()<<endl;
410 }
411 }
412 } else {
413 apps_file << "[app]"<<it->first->toString()<<endl;
414 }
356 if (a.workspace_remember) { 415 if (a.workspace_remember) {
357 apps_file << " [Workspace]\t{" << a.workspace << "}" << endl; 416 apps_file << " [Workspace]\t{" << a.workspace << "}" << endl;
358 } 417 }
@@ -541,7 +600,7 @@ void Remember::forgetAttrib(WinClient &winclient, Attribute attrib) {
541 } 600 }
542} 601}
543 602
544void Remember::setupWindow(FluxboxWindow &win) { 603void Remember::setupFrame(FluxboxWindow &win) {
545 WinClient &winclient = win.winClient(); 604 WinClient &winclient = win.winClient();
546 605
547 // we don't touch the window if it is a transient 606 // we don't touch the window if it is a transient
@@ -573,7 +632,10 @@ void Remember::setupWindow(FluxboxWindow &win) {
573 if (app == 0) 632 if (app == 0)
574 return; // nothing to do 633 return; // nothing to do
575 634
576 BScreen &screen = win.screen(); 635 if (app->is_grouped && app->group == 0)
636 app->group = &win;
637
638 BScreen &screen = winclient.screen();
577 639
578 if (app->workspace_remember) { 640 if (app->workspace_remember) {
579 // TODO: fix placement to initialise properly 641 // TODO: fix placement to initialise properly
@@ -611,10 +673,29 @@ void Remember::setupWindow(FluxboxWindow &win) {
611 673
612} 674}
613 675
676void Remember::setupClient(WinClient &winclient) {
677
678 Application *app = find(winclient);
679 if (app == 0)
680 return; // nothing to do
681
682 if (winclient.fbwindow() == 0 && app->is_grouped && app->group) {
683 app->group->attachClient(winclient);
684 }
685}
686
614void Remember::updateWindowClose(FluxboxWindow &win) { 687void Remember::updateWindowClose(FluxboxWindow &win) {
615 // This doesn't work at present since fluxbox.cc is missing the windowclose stuff. 688 // This doesn't work at present since fluxbox.cc is missing the windowclose stuff.
616 // I don't trust it (particularly winClient()) while this is the case 689 // I don't trust it (particularly winClient()) while this is the case
617 690
691 // scan all winclients and remove this fbw
692 Patterns::iterator it = m_pats.begin();
693 while (it != m_pats.end()) {
694 if (&win == it->second->group)
695 it->second->group = 0;
696 ++it;
697 }
698
618 return; 699 return;
619 700
620 WinClient &winclient = win.winClient(); 701 WinClient &winclient = win.winClient();