aboutsummaryrefslogtreecommitdiff
path: root/src/Remember.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Remember.cc')
-rw-r--r--src/Remember.cc130
1 files changed, 79 insertions, 51 deletions
diff --git a/src/Remember.cc b/src/Remember.cc
index e74ace2..21e078e 100644
--- a/src/Remember.cc
+++ b/src/Remember.cc
@@ -59,7 +59,7 @@
59#ifdef HAVE_SSTREAM 59#ifdef HAVE_SSTREAM
60#include <sstream> 60#include <sstream>
61#define FB_istringstream istringstream 61#define FB_istringstream istringstream
62#elif HAVE_STRSTREAM 62#elif HAVE_STRSTREAM
63#include <strstream> 63#include <strstream>
64#define FB_istringstream istrstream 64#define FB_istringstream istrstream
65#else 65#else
@@ -75,9 +75,9 @@ public:
75 RememberMenuItem(const char *label, Remember &remember, 75 RememberMenuItem(const char *label, Remember &remember,
76 FluxboxWindow &fbwin, 76 FluxboxWindow &fbwin,
77 Remember::Attribute attrib) : 77 Remember::Attribute attrib) :
78 FbTk::MenuItem(label), m_remember(remember), 78 FbTk::MenuItem(label), m_remember(remember),
79 m_win(fbwin), m_attrib(attrib) { 79 m_win(fbwin), m_attrib(attrib) {
80 setToggleItem(true); 80 setToggleItem(true);
81 } 81 }
82 82
83 bool isSelected() const { 83 bool isSelected() const {
@@ -88,7 +88,7 @@ public:
88 } 88 }
89 89
90 bool isEnabled() const { 90 bool isEnabled() const {
91 if (m_attrib != Remember::REM_JUMPWORKSPACE) 91 if (m_attrib != Remember::REM_JUMPWORKSPACE)
92 return true; 92 return true;
93 else if (m_win.numClients()) 93 else if (m_win.numClients())
94 return (m_remember.isRemembered(m_win.winClient(), Remember::REM_WORKSPACE)); 94 return (m_remember.isRemembered(m_win.winClient(), Remember::REM_WORKSPACE));
@@ -126,17 +126,19 @@ FbTk::Menu *createRememberMenu(Remember &remember, FluxboxWindow &win, bool enab
126 menu->updateMenu(); 126 menu->updateMenu();
127 return menu; 127 return menu;
128 } 128 }
129 129
130 _FB_USES_NLS; 130 _FB_USES_NLS;
131 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Workspace, "Workspace", "Remember Workspace"), 131 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Workspace, "Workspace", "Remember Workspace"),
132 remember, win, Remember::REM_WORKSPACE)); 132 remember, win, Remember::REM_WORKSPACE));
133 menu->insert(new RememberMenuItem(_FBTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"), 133 menu->insert(new RememberMenuItem(_FBTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"),
134 remember, win, Remember::REM_JUMPWORKSPACE)); 134 remember, win, Remember::REM_JUMPWORKSPACE));
135 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - windth width and height"), 135 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Head, "Head", "Remember Head"),
136 remember, win, Remember::REM_HEAD));
137 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - with width and height"),
136 remember, win, Remember::REM_DIMENSIONS)); 138 remember, win, Remember::REM_DIMENSIONS));
137 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"), 139 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"),
138 remember, win, Remember::REM_POSITION)); 140 remember, win, Remember::REM_POSITION));
139 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Sticky, "Sticky", "Remember Sticky"), 141 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Sticky, "Sticky", "Remember Sticky"),
140 remember, win, Remember::REM_STUCKSTATE)); 142 remember, win, Remember::REM_STUCKSTATE));
141 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Decorations, "Decorations", "Remember window decorations"), 143 menu->insert(new RememberMenuItem(_FBTEXT(Remember, Decorations, "Decorations", "Remember window decorations"),
142 remember, win, Remember::REM_DECOSTATE)); 144 remember, win, Remember::REM_DECOSTATE));
@@ -160,8 +162,8 @@ bool handleStartupItem(const string &line, int offset) {
160 162
161 // accept some options, for now only "screen=NN" 163 // accept some options, for now only "screen=NN"
162 // these option are given in parentheses before the command 164 // these option are given in parentheses before the command
163 next = FbTk::StringUtil::getStringBetween(str, 165 next = FbTk::StringUtil::getStringBetween(str,
164 line.c_str() + offset, 166 line.c_str() + offset,
165 '(', ')'); 167 '(', ')');
166 if (next > 0) { 168 if (next > 0) {
167 // there are some options 169 // there are some options
@@ -187,8 +189,8 @@ bool handleStartupItem(const string &line, int offset) {
187 next = 0; 189 next = 0;
188 } 190 }
189 191
190 next = FbTk::StringUtil::getStringBetween(str, 192 next = FbTk::StringUtil::getStringBetween(str,
191 line.c_str() + offset + next, 193 line.c_str() + offset + next,
192 '{', '}'); 194 '{', '}');
193 195
194 if (next <= 0) { 196 if (next <= 0) {
@@ -212,17 +214,18 @@ Application::Application(bool grouped)
212 : is_grouped(grouped), 214 : is_grouped(grouped),
213 group(0) 215 group(0)
214{ 216{
215 decostate_remember = 217 decostate_remember =
216 dimensions_remember = 218 dimensions_remember =
217 focushiddenstate_remember = 219 focushiddenstate_remember =
218 iconhiddenstate_remember = 220 iconhiddenstate_remember =
219 jumpworkspace_remember = 221 jumpworkspace_remember =
220 layer_remember = 222 layer_remember =
221 position_remember = 223 position_remember =
222 shadedstate_remember = 224 shadedstate_remember =
223 stuckstate_remember = 225 stuckstate_remember =
224 tabstate_remember = 226 tabstate_remember =
225 workspace_remember = 227 workspace_remember =
228 head_remember =
226 save_on_close_remember = false; 229 save_on_close_remember = false;
227} 230}
228 231
@@ -264,7 +267,7 @@ Application* Remember::find(WinClient &winclient) {
264 return wc_it->second; 267 return wc_it->second;
265 else { 268 else {
266 Patterns::iterator it = m_pats.begin(); 269 Patterns::iterator it = m_pats.begin();
267 for (; it != m_pats.end(); it++) 270 for (; it != m_pats.end(); it++)
268 if (it->first->match(winclient)) { 271 if (it->first->match(winclient)) {
269 it->first->addMatch(); 272 it->first->addMatch();
270 m_clients[&winclient] = it->second; 273 m_clients[&winclient] = it->second;
@@ -304,8 +307,8 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
304 continue; //the line is commented or blank 307 continue; //the line is commented or blank
305 int parse_pos = 0, err = 0; 308 int parse_pos = 0, err = 0;
306 string str_key, str_option, str_label; 309 string str_key, str_option, str_label;
307 err = FbTk::StringUtil::getStringBetween(str_key, 310 err = FbTk::StringUtil::getStringBetween(str_key,
308 line.c_str(), 311 line.c_str(),
309 '[', ']'); 312 '[', ']');
310 if (err > 0) { 313 if (err > 0) {
311 int tmp; 314 int tmp;
@@ -317,8 +320,8 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
317 } 320 }
318 if (err > 0 ) { 321 if (err > 0 ) {
319 parse_pos += err; 322 parse_pos += err;
320 err = FbTk::StringUtil::getStringBetween(str_label, 323 err = FbTk::StringUtil::getStringBetween(str_label,
321 line.c_str() + parse_pos, 324 line.c_str() + parse_pos,
322 '{', '}'); 325 '{', '}');
323 if (err>0) { 326 if (err>0) {
324 parse_pos += err; 327 parse_pos += err;
@@ -333,6 +336,9 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
333 FB_istringstream iss(str_label.c_str()); 336 FB_istringstream iss(str_label.c_str());
334 iss >> w; 337 iss >> w;
335 app.rememberWorkspace(w); 338 app.rememberWorkspace(w);
339 } else if (str_key == "Head") {
340 int h = atoi(str_label.c_str());
341 app.rememberHead(h);
336 } else if (str_key == "Layer") { 342 } else if (str_key == "Layer") {
337 unsigned int l; 343 unsigned int l;
338 if (str_label == "DESKTOP") { 344 if (str_label == "DESKTOP") {
@@ -366,7 +372,7 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
366 unsigned int y= 0; 372 unsigned int y= 0;
367 // more info about the parameter 373 // more info about the parameter
368 // in ::rememberPosition 374 // in ::rememberPosition
369 375
370 if ( str_option.length() ) 376 if ( str_option.length() )
371 { 377 {
372 if ( str_option == "UPPERLEFT" ) r= POS_UPPERLEFT; 378 if ( str_option == "UPPERLEFT" ) r= POS_UPPERLEFT;
@@ -389,9 +395,9 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
389 } else if (str_key == "Tab") { 395 } else if (str_key == "Tab") {
390 app.rememberTabstate((str_label=="yes")); 396 app.rememberTabstate((str_label=="yes"));
391 } else if (str_key == "FocusHidden") { 397 } else if (str_key == "FocusHidden") {
392 app.rememberFocusHiddenstate((str_label=="yes")); 398 app.rememberFocusHiddenstate((str_label=="yes"));
393 } else if (str_key == "IconHidden") { 399 } else if (str_key == "IconHidden") {
394 app.rememberIconHiddenstate((str_label=="yes")); 400 app.rememberIconHiddenstate((str_label=="yes"));
395 } else if (str_key == "Hidden") { 401 } else if (str_key == "Hidden") {
396 app.rememberIconHiddenstate((str_label=="yes")); 402 app.rememberIconHiddenstate((str_label=="yes"));
397 app.rememberFocusHiddenstate((str_label=="yes")); 403 app.rememberFocusHiddenstate((str_label=="yes"));
@@ -402,7 +408,7 @@ int Remember::parseApp(ifstream &file, Application &app, string *first_line) {
402 app.rememberDecostate((unsigned int) 0xfffffff); 408 app.rememberDecostate((unsigned int) 0xfffffff);
403 } else if (str_label == "TINY") { 409 } else if (str_label == "TINY") {
404 app.rememberDecostate((unsigned int) 410 app.rememberDecostate((unsigned int)
405 FluxboxWindow::DECORM_TITLEBAR 411 FluxboxWindow::DECORM_TITLEBAR
406 | FluxboxWindow::DECORM_ICONIFY 412 | FluxboxWindow::DECORM_ICONIFY
407 | FluxboxWindow::DECORM_MENU 413 | FluxboxWindow::DECORM_MENU
408 ); 414 );
@@ -468,8 +474,8 @@ void Remember::load() {
468 continue; 474 continue;
469 string key; 475 string key;
470 int err=0; 476 int err=0;
471 int pos = FbTk::StringUtil::getStringBetween(key, 477 int pos = FbTk::StringUtil::getStringBetween(key,
472 line.c_str(), 478 line.c_str(),
473 '[', ']'); 479 '[', ']');
474 480
475 if (pos > 0 && key == "app") { 481 if (pos > 0 && key == "app") {
@@ -502,7 +508,7 @@ void Remember::load() {
502 m_pats.push_back(make_pair(grouped_pats.front(), app)); 508 m_pats.push_back(make_pair(grouped_pats.front(), app));
503 grouped_pats.pop_front(); 509 grouped_pats.pop_front();
504 } 510 }
505 511
506 // we hit end... probably don't have attribs for the group 512 // we hit end... probably don't have attribs for the group
507 // so finish it off with an empty application 513 // so finish it off with an empty application
508 // otherwise parse the app 514 // otherwise parse the app
@@ -512,7 +518,7 @@ void Remember::load() {
512 in_group = false; 518 in_group = false;
513 } else 519 } else
514 cerr<<"Error in apps file on line "<<row<<"."<<endl; 520 cerr<<"Error in apps file on line "<<row<<"."<<endl;
515 521
516 } 522 }
517 } else { 523 } else {
518#ifdef DEBUG 524#ifdef DEBUG
@@ -566,6 +572,9 @@ void Remember::save() {
566 if (a.workspace_remember) { 572 if (a.workspace_remember) {
567 apps_file << " [Workspace]\t{" << a.workspace << "}" << endl; 573 apps_file << " [Workspace]\t{" << a.workspace << "}" << endl;
568 } 574 }
575 if (a.head_remember) {
576 apps_file << " [Head]\t{" << a.head << "}" << endl;
577 }
569 if (a.dimensions_remember) { 578 if (a.dimensions_remember) {
570 apps_file << " [Dimensions]\t{" << a.w << " " << a.h << "}" << endl; 579 apps_file << " [Dimensions]\t{" << a.w << " " << a.h << "}" << endl;
571 } 580 }
@@ -581,22 +590,22 @@ void Remember::save() {
581 if (a.decostate_remember) { 590 if (a.decostate_remember) {
582 switch (a.decostate) { 591 switch (a.decostate) {
583 case (0) : 592 case (0) :
584 apps_file << " [Deco]\t{NONE}" << endl; 593 apps_file << " [Deco]\t{NONE}" << endl;
585 break; 594 break;
586 case (0xffffffff): 595 case (0xffffffff):
587 case (FluxboxWindow::DECORM_LAST - 1): 596 case (FluxboxWindow::DECORM_LAST - 1):
588 apps_file << " [Deco]\t{NORMAL}" << endl; 597 apps_file << " [Deco]\t{NORMAL}" << endl;
589 break; 598 break;
590 case (FluxboxWindow::DECORM_TITLEBAR 599 case (FluxboxWindow::DECORM_TITLEBAR
591 | FluxboxWindow::DECORM_ICONIFY 600 | FluxboxWindow::DECORM_ICONIFY
592 | FluxboxWindow::DECORM_MENU): 601 | FluxboxWindow::DECORM_MENU):
593 apps_file << " [Deco]\t{TOOL}" << endl; 602 apps_file << " [Deco]\t{TOOL}" << endl;
594 break; 603 break;
595 case (FluxboxWindow::DECORM_TITLEBAR 604 case (FluxboxWindow::DECORM_TITLEBAR
596 | FluxboxWindow::DECORM_MENU): 605 | FluxboxWindow::DECORM_MENU):
597 apps_file << " [Deco]\t{TINY}" << endl; 606 apps_file << " [Deco]\t{TINY}" << endl;
598 break; 607 break;
599 case (FluxboxWindow::DECORM_BORDER 608 case (FluxboxWindow::DECORM_BORDER
600 | FluxboxWindow::DECORM_MENU): 609 | FluxboxWindow::DECORM_MENU):
601 apps_file << " [Deco]\t{BORDER}" << endl; 610 apps_file << " [Deco]\t{BORDER}" << endl;
602 break; 611 break;
@@ -608,7 +617,7 @@ void Remember::save() {
608 617
609 if (a.focushiddenstate_remember || a.iconhiddenstate_remember) { 618 if (a.focushiddenstate_remember || a.iconhiddenstate_remember) {
610 if (a.focushiddenstate_remember && a.iconhiddenstate_remember && 619 if (a.focushiddenstate_remember && a.iconhiddenstate_remember &&
611 a.focushiddenstate && a.iconhiddenstate) 620 a.focushiddenstate && a.iconhiddenstate)
612 apps_file << " [Hidden]\t{" << ((a.focushiddenstate)?"yes":"no") << "}" << endl; 621 apps_file << " [Hidden]\t{" << ((a.focushiddenstate)?"yes":"no") << "}" << endl;
613 else if (a.focushiddenstate_remember) { 622 else if (a.focushiddenstate_remember) {
614 apps_file << " [FocusHidden]\t{" << ((a.focushiddenstate)?"yes":"no") << "}" << endl; 623 apps_file << " [FocusHidden]\t{" << ((a.focushiddenstate)?"yes":"no") << "}" << endl;
@@ -639,6 +648,9 @@ bool Remember::isRemembered(WinClient &winclient, Attribute attrib) {
639 case REM_WORKSPACE: 648 case REM_WORKSPACE:
640 return app->workspace_remember; 649 return app->workspace_remember;
641 break; 650 break;
651 case REM_HEAD:
652 return app->head_remember;
653 break;
642 case REM_DIMENSIONS: 654 case REM_DIMENSIONS:
643 return app->dimensions_remember; 655 return app->dimensions_remember;
644 break; 656 break;
@@ -690,6 +702,9 @@ void Remember::rememberAttrib(WinClient &winclient, Attribute attrib) {
690 case REM_WORKSPACE: 702 case REM_WORKSPACE:
691 app->rememberWorkspace(win->workspaceNumber()); 703 app->rememberWorkspace(win->workspaceNumber());
692 break; 704 break;
705 case REM_HEAD:
706 app->rememberHead(win->screen().getHead(win->fbWindow()));
707 break;
693 case REM_DIMENSIONS: 708 case REM_DIMENSIONS:
694 app->rememberDimensions(win->width(), win->height()); 709 app->rememberDimensions(win->width(), win->height());
695 break; 710 break;
@@ -741,6 +756,9 @@ void Remember::forgetAttrib(WinClient &winclient, Attribute attrib) {
741 case REM_WORKSPACE: 756 case REM_WORKSPACE:
742 app->forgetWorkspace(); 757 app->forgetWorkspace();
743 break; 758 break;
759 case REM_HEAD:
760 app->forgetHead();
761 break;
744 case REM_DIMENSIONS: 762 case REM_DIMENSIONS:
745 app->forgetDimensions(); 763 app->forgetDimensions();
746 break; 764 break;
@@ -790,11 +808,11 @@ void Remember::setupFrame(FluxboxWindow &win) {
790 win.addExtraMenu(_FBTEXT(Remember, MenuItemName, "Remember...", "Remember item in menu"), 808 win.addExtraMenu(_FBTEXT(Remember, MenuItemName, "Remember...", "Remember item in menu"),
791 createRememberMenu(*this, win, (winclient.transientFor() == 0))); 809 createRememberMenu(*this, win, (winclient.transientFor() == 0)));
792 810
793 if (winclient.transientFor()) 811 if (winclient.transientFor())
794 return; 812 return;
795 813
796 Application *app = find(winclient); 814 Application *app = find(winclient);
797 if (app == 0) 815 if (app == 0)
798 return; // nothing to do 816 return; // nothing to do
799 817
800 if (app->is_grouped && app->group == 0) 818 if (app->is_grouped && app->group == 0)
@@ -804,41 +822,51 @@ void Remember::setupFrame(FluxboxWindow &win) {
804 822
805 if (app->workspace_remember) { 823 if (app->workspace_remember) {
806 // TODO: fix placement to initialise properly 824 // TODO: fix placement to initialise properly
807 screen.reassociateWindow(&win, app->workspace, true); 825 screen.reassociateWindow(&win, app->workspace, true);
808 if (app->jumpworkspace_remember) 826 if (app->jumpworkspace_remember)
809 screen.changeWorkspaceID(app->workspace); 827 screen.changeWorkspaceID(app->workspace);
810 } 828 }
811 829
830 if (app->head_remember) {
831 win.screen().setOnHead<FluxboxWindow>(win, app->head);
832 }
833
812 if (app->decostate_remember) 834 if (app->decostate_remember)
813 win.setDecorationMask(app->decostate); 835 win.setDecorationMask(app->decostate);
814 836
815 837
816 if (app->dimensions_remember) 838 if (app->dimensions_remember)
817 win.resize(app->w, app->h); 839 win.resize(app->w, app->h);
818 840
841 int head = screen.getHead(win.fbWindow());
842
819 if (app->position_remember) { 843 if (app->position_remember) {
844
820 switch (app->refc) { 845 switch (app->refc) {
821 default: 846 default:
822 case POS_UPPERLEFT: // upperleft corner 847 case POS_UPPERLEFT: // upperleft corner
823 win.move(app->x, app->y); 848 win.move(screen.getHeadX(head) + app->x,
849 screen.getHeadY(head) + app->y);
824 break; 850 break;
825 case POS_UPPERRIGHT: // upperright corner 851 case POS_UPPERRIGHT: // upperright corner
826 win.move(screen.width() - win.width() - app->x, app->y); 852 win.move(screen.getHeadX(head) + screen.getHeadWidth(head) - win.width() - app->x,
853 screen.getHeadY(head) + app->y);
827 break; 854 break;
828 case POS_LOWERLEFT: // lowerleft corner 855 case POS_LOWERLEFT: // lowerleft corner
829 win.move(app->x, screen.height() - win.height() - app->y); 856 win.move(screen.getHeadX(head) + app->x,
857 screen.getHeadHeight(head) - win.height() - app->y);
830 break; 858 break;
831 case POS_LOWERRIGHT: // lowerright corner 859 case POS_LOWERRIGHT: // lowerright corner
832 win.move(screen.width() - win.width() - app->x, 860 win.move(screen.getHeadWidth(head) - win.width() - app->x,
833 screen.height() - win.height() - app->y); 861 screen.getHeadHeight(head) - win.height() - app->y);
834 break; 862 break;
835 case POS_CENTER: // center of the screen, windows topleft corner is on the center 863 case POS_CENTER: // center of the screen, windows topleft corner is on the center
836 win.move((screen.width() / 2) + app->x, 864 win.move((screen.getHeadWidth(head) / 2) + app->x,
837 (screen.height() / 2) + app->y); 865 (screen.getHeadHeight(head) / 2) + app->y);
838 break; 866 break;
839 case POS_WINCENTER: // the window is centered REALLY upon the center 867 case POS_WINCENTER: // the window is centered REALLY upon the center
840 win.move((screen.width() / 2) - ( win.width() / 2 ) + app->x, 868 win.move((screen.getHeadWidth(head) / 2) - ( win.width() / 2 ) + app->x,
841 (screen.height() / 2) - ( win.height() / 2 ) + app->y); 869 (screen.getHeadHeight(head) / 2) - ( win.height() / 2 ) + app->y);
842 break; 870 break;
843 }; 871 };
844 } 872 }
@@ -870,7 +898,7 @@ void Remember::setupFrame(FluxboxWindow &win) {
870void Remember::setupClient(WinClient &winclient) { 898void Remember::setupClient(WinClient &winclient) {
871 899
872 Application *app = find(winclient); 900 Application *app = find(winclient);
873 if (app == 0) 901 if (app == 0)
874 return; // nothing to do 902 return; // nothing to do
875 903
876 if (winclient.fbwindow() == 0 && app->is_grouped && app->group) { 904 if (winclient.fbwindow() == 0 && app->is_grouped && app->group) {