aboutsummaryrefslogtreecommitdiff
path: root/src/Remember.cc
diff options
context:
space:
mode:
authormarkt <markt>2007-03-31 17:11:59 (GMT)
committermarkt <markt>2007-03-31 17:11:59 (GMT)
commit491c0e523429f45c02f5da04f8b7fbb45095e1e1 (patch)
tree78f86d25ea628dc6fe6ad394053610a6e6e3420d /src/Remember.cc
parent8f8d8bd0f1ab31eb68d6baf42254b01b1d240510 (diff)
downloadfluxbox-491c0e523429f45c02f5da04f8b7fbb45095e1e1.zip
fluxbox-491c0e523429f45c02f5da04f8b7fbb45095e1e1.tar.bz2
pattern matching for window commands and [group] in apps file
Diffstat (limited to 'src/Remember.cc')
-rw-r--r--src/Remember.cc45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/Remember.cc b/src/Remember.cc
index e0a7b0f..6f86ade 100644
--- a/src/Remember.cc
+++ b/src/Remember.cc
@@ -230,8 +230,8 @@ bool handleStartupItem(const string &line, int offset) {
230}; // end anonymous namespace 230}; // end anonymous namespace
231 231
232 232
233Application::Application(int grouped) 233Application::Application(bool grouped, ClientPattern *pat)
234 : is_grouped(grouped) 234 : is_grouped(grouped), group_pattern(pat)
235{ 235{
236 decostate_remember = 236 decostate_remember =
237 dimensions_remember = 237 dimensions_remember =
@@ -337,7 +337,7 @@ Application* Remember::find(WinClient &winclient) {
337 337
338Application * Remember::add(WinClient &winclient) { 338Application * Remember::add(WinClient &winclient) {
339 ClientPattern *p = new ClientPattern(); 339 ClientPattern *p = new ClientPattern();
340 Application *app = new Application(0); 340 Application *app = new Application(false);
341 341
342 // by default, we match against the WMClass of a window. 342 // by default, we match against the WMClass of a window.
343 string win_name = p->getProperty(ClientPattern::NAME, winclient); 343 string win_name = p->getProperty(ClientPattern::NAME, winclient);
@@ -530,11 +530,13 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
530 effectively moved into the new 530 effectively moved into the new
531*/ 531*/
532 532
533Application *Remember::findMatchingPatterns(ClientPattern *pat, Patterns *patlist, int is_group) { 533Application *Remember::findMatchingPatterns(ClientPattern *pat, Patterns *patlist, bool is_group, ClientPattern *match_pat) {
534 Patterns::iterator it = patlist->begin(); 534 Patterns::iterator it = patlist->begin();
535 Patterns::iterator it_end = patlist->end(); 535 Patterns::iterator it_end = patlist->end();
536 for (; it != it_end; ++it) { 536 for (; it != it_end; ++it) {
537 if (it->first->equals(*pat) && is_group == it->second->is_grouped) { 537 if (it->first->equals(*pat) && is_group == it->second->is_grouped &&
538 ((match_pat == 0 && *it->second->group_pattern == 0) ||
539 (match_pat && match_pat->equals(**it->second->group_pattern)))) {
538 Application *ret = it->second; 540 Application *ret = it->second;
539 541
540 // find any previous or subsequent matching ones and delete 542 // find any previous or subsequent matching ones and delete
@@ -586,7 +588,8 @@ void Remember::reconfigure() {
586 if (!apps_file.eof()) { 588 if (!apps_file.eof()) {
587 string line; 589 string line;
588 int row = 0; 590 int row = 0;
589 int in_group = 0; 591 bool in_group = false;
592 ClientPattern *pat = 0;
590 list<ClientPattern *> grouped_pats; 593 list<ClientPattern *> grouped_pats;
591 while (getline(apps_file, line) && ! apps_file.eof()) { 594 while (getline(apps_file, line) && ! apps_file.eof()) {
592 row++; 595 row++;
@@ -602,11 +605,11 @@ void Remember::reconfigure() {
602 605
603 if (pos > 0 && strcasecmp(key.c_str(), "app") == 0) { 606 if (pos > 0 && strcasecmp(key.c_str(), "app") == 0) {
604 ClientPattern *pat = new ClientPattern(line.c_str() + pos); 607 ClientPattern *pat = new ClientPattern(line.c_str() + pos);
605 if (in_group == 0) { 608 if (!in_group) {
606 if ((err = pat->error()) == 0) { 609 if ((err = pat->error()) == 0) {
607 Application *app = findMatchingPatterns(pat, old_pats, 0); 610 Application *app = findMatchingPatterns(pat, old_pats, false);
608 if (!app) 611 if (!app)
609 app = new Application(0); 612 app = new Application(false);
610 613
611 m_pats->push_back(make_pair(pat, app)); 614 m_pats->push_back(make_pair(pat, app));
612 row += parseApp(apps_file, *app); 615 row += parseApp(apps_file, *app);
@@ -625,12 +628,9 @@ void Remember::reconfigure() {
625 // save the item even if it was bad (aren't we nice) 628 // save the item even if it was bad (aren't we nice)
626 m_startups.push_back(line.substr(pos)); 629 m_startups.push_back(line.substr(pos));
627 } else if (pos > 0 && strcasecmp(key.c_str(), "group") == 0) { 630 } else if (pos > 0 && strcasecmp(key.c_str(), "group") == 0) {
628 in_group = Application::IS_GROUPED; 631 in_group = true;
629 pos = FbTk::StringUtil::getStringBetween(key, 632 if (line.find('(') != string::npos)
630 line.c_str() + pos, 633 pat = new ClientPattern(line.c_str() + pos);
631 '(', ')');
632 if (pos > 0 && strcasecmp(key.c_str(), "workspace") == 0)
633 in_group |= Application::MATCH_WORKSPACE;
634 } else if (in_group) { 634 } else if (in_group) {
635 // otherwise assume that it is the start of the attributes 635 // otherwise assume that it is the start of the attributes
636 Application *app = 0; 636 Application *app = 0;
@@ -638,12 +638,12 @@ void Remember::reconfigure() {
638 list<ClientPattern *>::iterator it = grouped_pats.begin(); 638 list<ClientPattern *>::iterator it = grouped_pats.begin();
639 list<ClientPattern *>::iterator it_end = grouped_pats.end(); 639 list<ClientPattern *>::iterator it_end = grouped_pats.end();
640 while (!app && it != it_end) { 640 while (!app && it != it_end) {
641 app = findMatchingPatterns(*it, old_pats, in_group); 641 app = findMatchingPatterns(*it, old_pats, in_group, pat);
642 ++it; 642 ++it;
643 } 643 }
644 644
645 if (!app) 645 if (!app)
646 app = new Application(in_group); 646 app = new Application(in_group, pat);
647 647
648 while (!grouped_pats.empty()) { 648 while (!grouped_pats.empty()) {
649 // associate all the patterns with this app 649 // associate all the patterns with this app
@@ -657,7 +657,7 @@ void Remember::reconfigure() {
657 if (!(pos>0 && strcasecmp(key.c_str(), "end") == 0)) { 657 if (!(pos>0 && strcasecmp(key.c_str(), "end") == 0)) {
658 row += parseApp(apps_file, *app, &line); 658 row += parseApp(apps_file, *app, &line);
659 } 659 }
660 in_group = 0; 660 in_group = false;
661 } else 661 } else
662 cerr<<"Error in apps file on line "<<row<<"."<<endl; 662 cerr<<"Error in apps file on line "<<row<<"."<<endl;
663 663
@@ -735,8 +735,8 @@ void Remember::save() {
735 grouped_apps.insert(&a); 735 grouped_apps.insert(&a);
736 // otherwise output this whole group 736 // otherwise output this whole group
737 apps_file << "[group]"; 737 apps_file << "[group]";
738 if (a.is_grouped & Application::MATCH_WORKSPACE) 738 if (*a.group_pattern)
739 apps_file << " (workspace)"; 739 apps_file << " " << a.group_pattern->toString();
740 apps_file << endl; 740 apps_file << endl;
741 741
742 Patterns::iterator git = m_pats->begin(); 742 Patterns::iterator git = m_pats->begin();
@@ -1159,10 +1159,7 @@ FluxboxWindow *Remember::findGroup(Application *app, BScreen &screen) {
1159 for (; it != it_end; ++it) { 1159 for (; it != it_end; ++it) {
1160 if (it->second == app && it->first->fbwindow() && 1160 if (it->second == app && it->first->fbwindow() &&
1161 &screen == &it->first->screen() && 1161 &screen == &it->first->screen() &&
1162 (!(app->is_grouped & Application::MATCH_WORKSPACE) || 1162 (!*app->group_pattern || app->group_pattern->match(*it->first)))
1163 it->first->fbwindow()->workspaceNumber() ==
1164 screen.currentWorkspaceID()))
1165
1166 return it->first->fbwindow(); 1163 return it->first->fbwindow();
1167 } 1164 }
1168 1165