aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2010-09-17 13:51:16 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2010-09-17 13:51:16 (GMT)
commitd3eabeb805fdbd162c0743ed86a67e014e37c097 (patch)
treede06d61dd922934e739b9a33008c2da4f721b9d2
parente84c64f7be701e04ec2a2e0fbf980aa4fc9685ad (diff)
downloadfluxbox_paul-d3eabeb805fdbd162c0743ed86a67e014e37c097.zip
fluxbox_paul-d3eabeb805fdbd162c0743ed86a67e014e37c097.tar.bz2
moved commandline parsing to its own function
-rw-r--r--src/Screen.cc162
-rw-r--r--src/main.cc56
2 files changed, 132 insertions, 86 deletions
diff --git a/src/Screen.cc b/src/Screen.cc
index daa87dc..0677a14 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -183,7 +183,7 @@ int calcSquareDistance(int x1, int y1, int x2, int y2) {
183 183
184class TabPlacementMenuItem: public FbTk::RadioMenuItem { 184class TabPlacementMenuItem: public FbTk::RadioMenuItem {
185public: 185public:
186 TabPlacementMenuItem(const FbTk::FbString & label, BScreen &screen, 186 TabPlacementMenuItem(FbTk::FbString & label, BScreen &screen,
187 FbWinFrame::TabPlacement place, 187 FbWinFrame::TabPlacement place,
188 FbTk::RefCount<FbTk::Command<void> > &cmd): 188 FbTk::RefCount<FbTk::Command<void> > &cmd):
189 FbTk::RadioMenuItem(label, cmd), 189 FbTk::RadioMenuItem(label, cmd),
@@ -208,28 +208,6 @@ void clampMenuDelay(int& delay) {
208 delay = FbTk::Util::clamp(delay, 0, 5000); 208 delay = FbTk::Util::clamp(delay, 0, 5000);
209} 209}
210 210
211
212struct TabPlacementString {
213 FbWinFrame::TabPlacement placement;
214 const char* str;
215};
216
217const TabPlacementString placement_strings[] = {
218 { FbWinFrame::TOPLEFT, "TopLeft" },
219 { FbWinFrame::TOP, "Top" },
220 { FbWinFrame::TOPRIGHT, "TopRight" },
221 { FbWinFrame::BOTTOMLEFT, "BottomLeft" },
222 { FbWinFrame::BOTTOM, "Bottom" },
223 { FbWinFrame::BOTTOMRIGHT, "BottomRight" },
224 { FbWinFrame::LEFTBOTTOM, "LeftBottom" },
225 { FbWinFrame::LEFT, "Left" },
226 { FbWinFrame::LEFTTOP, "LeftTop" },
227 { FbWinFrame::RIGHTBOTTOM, "RightBottom" },
228 { FbWinFrame::RIGHT, "Right" },
229 { FbWinFrame::RIGHTTOP, "RightTop" }
230};
231
232
233} // end anonymous namespace 211} // end anonymous namespace
234 212
235 213
@@ -239,25 +217,77 @@ namespace FbTk {
239template<> 217template<>
240string FbTk::Resource<FbWinFrame::TabPlacement>:: 218string FbTk::Resource<FbWinFrame::TabPlacement>::
241getString() const { 219getString() const {
242 220 switch (m_value) {
243 size_t i = (m_value == FbTk::Util::clamp(m_value, FbWinFrame::TOPLEFT, FbWinFrame::RIGHTTOP) 221 case FbWinFrame::TOPLEFT:
244 ? m_value 222 return string("TopLeft");
245 : FbWinFrame::DEFAULT) - 1; 223 break;
246 return placement_strings[i].str; 224 case FbWinFrame::BOTTOMLEFT:
225 return string("BottomLeft");
226 break;
227 case FbWinFrame::TOP:
228 return string("Top");
229 break;
230 case FbWinFrame::BOTTOM:
231 return string("Bottom");
232 break;
233 case FbWinFrame::TOPRIGHT:
234 return string("TopRight");
235 break;
236 case FbWinFrame::BOTTOMRIGHT:
237 return string("BottomRight");
238 break;
239 case FbWinFrame::LEFTTOP:
240 return string("LeftTop");
241 break;
242 case FbWinFrame::LEFT:
243 return string("Left");
244 break;
245 case FbWinFrame::LEFTBOTTOM:
246 return string("LeftBottom");
247 break;
248 case FbWinFrame::RIGHTTOP:
249 return string("RightTop");
250 break;
251 case FbWinFrame::RIGHT:
252 return string("Right");
253 break;
254 case FbWinFrame::RIGHTBOTTOM:
255 return string("RightBottom");
256 break;
257 }
258 //default string
259 return string("TopLeft");
247} 260}
248 261
249template<> 262template<>
250void FbTk::Resource<FbWinFrame::TabPlacement>:: 263void FbTk::Resource<FbWinFrame::TabPlacement>::
251setFromString(const char *strval) { 264setFromString(const char *strval) {
252 265 if (strcasecmp(strval, "TopLeft") == 0)
253 size_t i; 266 m_value = FbWinFrame::TOPLEFT;
254 for (i = 0; i < sizeof(placement_strings)/sizeof(TabPlacementString); ++i) { 267 else if (strcasecmp(strval, "BottomLeft") == 0)
255 if (strcasecmp(strval, placement_strings[i].str) == 0) { 268 m_value = FbWinFrame::BOTTOMLEFT;
256 m_value = placement_strings[i].placement; 269 else if (strcasecmp(strval, "Top") == 0)
257 return; 270 m_value = FbWinFrame::TOP;
258 } 271 else if (strcasecmp(strval, "Bottom") == 0)
259 } 272 m_value = FbWinFrame::BOTTOM;
260 setDefaultValue(); 273 else if (strcasecmp(strval, "TopRight") == 0)
274 m_value = FbWinFrame::TOPRIGHT;
275 else if (strcasecmp(strval, "BottomRight") == 0)
276 m_value = FbWinFrame::BOTTOMRIGHT;
277 else if (strcasecmp(strval, "LeftTop") == 0)
278 m_value = FbWinFrame::LEFTTOP;
279 else if (strcasecmp(strval, "Left") == 0)
280 m_value = FbWinFrame::LEFT;
281 else if (strcasecmp(strval, "LeftBottom") == 0)
282 m_value = FbWinFrame::LEFTBOTTOM;
283 else if (strcasecmp(strval, "RightTop") == 0)
284 m_value = FbWinFrame::RIGHTTOP;
285 else if (strcasecmp(strval, "Right") == 0)
286 m_value = FbWinFrame::RIGHT;
287 else if (strcasecmp(strval, "RightBottom") == 0)
288 m_value = FbWinFrame::RIGHTBOTTOM;
289 else
290 setDefaultValue();
261} 291}
262 292
263} // end namespace FbTk 293} // end namespace FbTk
@@ -1619,41 +1649,41 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1619 tab_width_item->setCommand(save_and_reconftabs); 1649 tab_width_item->setCommand(save_and_reconftabs);
1620 tab_menu->insert(tab_width_item); 1650 tab_menu->insert(tab_width_item);
1621 1651
1652
1653 typedef pair<FbTk::FbString, FbWinFrame::TabPlacement> PlacementP;
1654 typedef list<PlacementP> Placements;
1655 Placements place_menu;
1656
1622 // menu is 3 wide, 5 down 1657 // menu is 3 wide, 5 down
1623 struct PlacementP { 1658 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), FbWinFrame::TOPLEFT));
1624 const FbTk::FbString label; 1659 place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), FbWinFrame::LEFTTOP));
1625 FbWinFrame::TabPlacement placement; 1660 place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), FbWinFrame::LEFT));
1626 }; 1661 place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), FbWinFrame::LEFTBOTTOM));
1627 static const PlacementP place_menu[] = { 1662 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), FbWinFrame::BOTTOMLEFT));
1628 1663 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), FbWinFrame::TOP));
1629 { _FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), FbWinFrame::TOPLEFT}, 1664 place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT));
1630 { _FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), FbWinFrame::LEFTTOP}, 1665 place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT));
1631 { _FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), FbWinFrame::LEFT}, 1666 place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT));
1632 { _FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), FbWinFrame::LEFTBOTTOM}, 1667 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), FbWinFrame::BOTTOM));
1633 { _FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), FbWinFrame::BOTTOMLEFT}, 1668 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), FbWinFrame::TOPRIGHT));
1634 { _FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), FbWinFrame::TOP}, 1669 place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), FbWinFrame::RIGHTTOP));
1635 { "", FbWinFrame::TOPLEFT}, 1670 place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), FbWinFrame::RIGHT));
1636 { "", FbWinFrame::TOPLEFT}, 1671 place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), FbWinFrame::RIGHTBOTTOM));
1637 { "", FbWinFrame::TOPLEFT}, 1672 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), FbWinFrame::BOTTOMRIGHT));
1638 { _FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), FbWinFrame::BOTTOM},
1639 { _FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), FbWinFrame::TOPRIGHT},
1640 { _FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), FbWinFrame::RIGHTTOP},
1641 { _FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), FbWinFrame::RIGHT},
1642 { _FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), FbWinFrame::RIGHTBOTTOM},
1643 { _FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), FbWinFrame::BOTTOMRIGHT}
1644 };
1645 1673
1646 tabplacement_menu->setMinimumSublevels(3); 1674 tabplacement_menu->setMinimumSublevels(3);
1647 // create items in sub menu 1675 // create items in sub menu
1648 for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { 1676 for (size_t i=0; i<15; ++i) {
1649 const PlacementP& p = place_menu[i]; 1677 FbTk::FbString &str = place_menu.front().first;
1650 if (p.label == "") { 1678 FbWinFrame::TabPlacement placement = place_menu.front().second;
1651 tabplacement_menu->insert(p.label); 1679 if (str == "") {
1680 tabplacement_menu->insert("");
1652 tabplacement_menu->setItemEnabled(i, false); 1681 tabplacement_menu->setItemEnabled(i, false);
1653 } else 1682 } else {
1654 tabplacement_menu->insert(new TabPlacementMenuItem(p.label, *this, p.placement, save_and_reconftabs)); 1683 tabplacement_menu->insert(new TabPlacementMenuItem(str, *this, placement, save_and_reconftabs));
1684 }
1685 place_menu.pop_front();
1655 } 1686 }
1656
1657 tabplacement_menu->updateMenu(); 1687 tabplacement_menu->updateMenu();
1658 1688
1659 menu.insert(tabmenu_label, tab_menu); 1689 menu.insert(tabmenu_label, tab_menu);
diff --git a/src/main.cc b/src/main.cc
index d65212b..dc42b27 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -182,14 +182,15 @@ static void showInfo(ostream &ostr) {
182 endl; 182 endl;
183} 183}
184 184
185int main(int argc, char **argv) { 185struct Options {
186 std::string session_display;
187 std::string rc_file;
188 std::string log_filename;
189 bool xsync;
190};
186 191
187 string session_display(""); 192static void parseOptions(int argc, char** argv, Options& opts) {
188 string rc_file;
189 string log_filename;
190 bool xsync = false;
191 193
192 FbTk::NLSInit("fluxbox.cat");
193 _FB_USES_NLS; 194 _FB_USES_NLS;
194 195
195 int i; 196 int i;
@@ -204,7 +205,7 @@ int main(int argc, char **argv) {
204 exit(EXIT_FAILURE); 205 exit(EXIT_FAILURE);
205 } 206 }
206 207
207 rc_file = argv[i]; 208 opts.rc_file = argv[i];
208 } else if (arg == "-display" || arg == "--display") { 209 } else if (arg == "-display" || arg == "--display") {
209 // check for -display option... to run on a display other than the one 210 // check for -display option... to run on a display other than the one
210 // set by the environment variable DISPLAY 211 // set by the environment variable DISPLAY
@@ -216,8 +217,8 @@ int main(int argc, char **argv) {
216 exit(EXIT_FAILURE); 217 exit(EXIT_FAILURE);
217 } 218 }
218 219
219 session_display = argv[i]; 220 opts.session_display = argv[i];
220 string display_env = "DISPLAY=" + session_display; 221 string display_env = "DISPLAY=" + opts.session_display;
221 if (putenv(const_cast<char *>(display_env.c_str()))) { 222 if (putenv(const_cast<char *>(display_env.c_str()))) {
222 cerr<<_FB_CONSOLETEXT(main, WarnDisplayEnv, 223 cerr<<_FB_CONSOLETEXT(main, WarnDisplayEnv,
223 "warning: couldn't set environment variable 'DISPLAY'", 224 "warning: couldn't set environment variable 'DISPLAY'",
@@ -226,16 +227,16 @@ int main(int argc, char **argv) {
226 } 227 }
227 } else if (arg == "-version" || arg == "-v" || arg == "--version") { 228 } else if (arg == "-version" || arg == "-v" || arg == "--version") {
228 // print current version string 229 // print current version string
229 cout << "Fluxbox " << __fluxbox_version << " : (c) 2001-2008 Fluxbox Team " << endl << endl; 230 cout << "Fluxbox " << __fluxbox_version << " : (c) 2001-2010 Fluxbox Team " << endl << endl;
230 exit(EXIT_SUCCESS); 231 exit(EXIT_SUCCESS);
231 } else if (arg == "-log" || arg == "--log") { 232 } else if (arg == "-log" || arg == "--log") {
232 if (++i >= argc) { 233 if (++i >= argc) {
233 cerr<<_FB_CONSOLETEXT(main, LOGRequiresArg, "error: '-log' needs an argument", "")<<endl; 234 cerr<<_FB_CONSOLETEXT(main, LOGRequiresArg, "error: '-log' needs an argument", "")<<endl;
234 exit(EXIT_FAILURE); 235 exit(EXIT_FAILURE);
235 } 236 }
236 log_filename = argv[i]; 237 opts.log_filename = argv[i];
237 } else if (arg == "-sync" || arg == "--sync") { 238 } else if (arg == "-sync" || arg == "--sync") {
238 xsync = true; 239 opts.xsync = true;
239 } else if (arg == "-help" || arg == "-h" || arg == "--help") { 240 } else if (arg == "-help" || arg == "-h" || arg == "--help") {
240 // print program usage and command line options 241 // print program usage and command line options
241 printf(_FB_CONSOLETEXT(main, Usage, 242 printf(_FB_CONSOLETEXT(main, Usage,
@@ -252,7 +253,7 @@ int main(int argc, char **argv) {
252 "-help\t\t\t\tdisplay this help text and exit.\n\n", 253 "-help\t\t\t\tdisplay this help text and exit.\n\n",
253 254
254 "Main usage string. Please lay it out nicely. There is one %s that is given the version").c_str(), 255 "Main usage string. Please lay it out nicely. There is one %s that is given the version").c_str(),
255 __fluxbox_version, "2001-2008"); 256 __fluxbox_version, "2001-2010");
256 exit(EXIT_SUCCESS); 257 exit(EXIT_SUCCESS);
257 } else if (arg == "-info" || arg == "-i" || arg == "--info") { 258 } else if (arg == "-info" || arg == "-i" || arg == "--info") {
258 showInfo(cout); 259 showInfo(cout);
@@ -268,23 +269,34 @@ int main(int argc, char **argv) {
268 FbTk::ThemeManager::instance().setVerbose(true); 269 FbTk::ThemeManager::instance().setVerbose(true);
269 } 270 }
270 } 271 }
272}
273
274
275
276int main(int argc, char **argv) {
277
278 FbTk::NLSInit("fluxbox.cat");
279
280 Options opts;
281 parseOptions(argc, argv, opts);
271 282
272#ifdef __EMX__ 283#ifdef __EMX__
273 _chdir2(getenv("X11ROOT")); 284 _chdir2(getenv("X11ROOT"));
274#endif // __EMX__ 285#endif // __EMX__
275 auto_ptr<Fluxbox> fluxbox; 286 auto_ptr<Fluxbox> fluxbox;
276 int exitcode=EXIT_FAILURE;
277 287
278 streambuf *outbuf = 0; 288 streambuf *outbuf = 0;
279 streambuf *errbuf = 0; 289 streambuf *errbuf = 0;
280 290
281 ofstream log_file(log_filename.c_str()); 291 ofstream log_file(opts.log_filename.c_str());
292
293 _FB_USES_NLS;
282 294
283 // setup log file 295 // setup log file
284 if (log_file) { 296 if (log_file.is_open()) {
285 cerr<<_FB_CONSOLETEXT(main, LoggingTo, "Logging to", "Logging to a file")<<": "<<log_filename<<endl; 297 cerr<<_FB_CONSOLETEXT(main, LoggingTo, "Logging to", "Logging to a file")<<": "<<opts.log_filename<<endl;
286 log_file<<"------------------------------------------"<<endl; 298 log_file<<"------------------------------------------"<<endl;
287 log_file<<_FB_CONSOLETEXT(main, LogFile, "Log File", "")<<": "<<log_filename<<endl; 299 log_file<<_FB_CONSOLETEXT(main, LogFile, "Log File", "")<<": "<<opts.log_filename<<endl;
288 showInfo(log_file); 300 showInfo(log_file);
289 log_file<<"------------------------------------------"<<endl; 301 log_file<<"------------------------------------------"<<endl;
290 // setup log to use cout and cerr stream 302 // setup log to use cout and cerr stream
@@ -292,10 +304,14 @@ int main(int argc, char **argv) {
292 errbuf = cerr.rdbuf(log_file.rdbuf()); 304 errbuf = cerr.rdbuf(log_file.rdbuf());
293 } 305 }
294 306
307 int exitcode = EXIT_FAILURE;
308
295 try { 309 try {
296 310
297 fluxbox.reset(new Fluxbox(argc, argv, session_display.c_str(), 311 fluxbox.reset(new Fluxbox(argc, argv,
298 rc_file.c_str(), xsync)); 312 opts.session_display.c_str(),
313 opts.rc_file.c_str(),
314 opts.xsync));
299 fluxbox->eventLoop(); 315 fluxbox->eventLoop();
300 316
301 exitcode = EXIT_SUCCESS; 317 exitcode = EXIT_SUCCESS;