aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2010-09-13 20:07:10 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2010-09-13 20:07:10 (GMT)
commitb10d58588ad7a50f91212acb19c3c2cc493cb3a4 (patch)
treee0fe40d242c90189fc78f5159ac20c8fc8c2dee7
parentdeb6a1ebf43f458b720abbc6a7180e9a8e04771a (diff)
downloadfluxbox_pavel-b10d58588ad7a50f91212acb19c3c2cc493cb3a4.zip
fluxbox_pavel-b10d58588ad7a50f91212acb19c3c2cc493cb3a4.tar.bz2
cosmetic code cleaning
* use FbTk::StringUtil::number2String() to avoid 'sprintf' * use FbTk::Util::clamp() * use FbTk::STLUtil::destroyAndClear() * whitespaces
-rw-r--r--src/FbWinFrame.cc13
-rw-r--r--src/fluxbox.cc67
2 files changed, 33 insertions, 47 deletions
diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc
index c8b1735..4c56d49 100644
--- a/src/FbWinFrame.cc
+++ b/src/FbWinFrame.cc
@@ -598,16 +598,9 @@ void FbWinFrame::addRightButton(FbTk::Button *btn) {
598} 598}
599 599
600void FbWinFrame::removeAllButtons() { 600void FbWinFrame::removeAllButtons() {
601 // destroy left side 601
602 while (!m_buttons_left.empty()) { 602 FbTk::STLUtil::destroyAndClear(m_buttons_left);
603 delete m_buttons_left.back(); 603 FbTk::STLUtil::destroyAndClear(m_buttons_right);
604 m_buttons_left.pop_back();
605 }
606 // destroy right side
607 while (!m_buttons_right.empty()) {
608 delete m_buttons_right.back();
609 m_buttons_right.pop_back();
610 }
611} 604}
612 605
613void FbWinFrame::createTab(FbTk::Button &button) { 606void FbWinFrame::createTab(FbTk::Button &button) {
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 1bc0d13..6780ef1 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -44,6 +44,7 @@
44#include "FbTk/ImageControl.hh" 44#include "FbTk/ImageControl.hh"
45#include "FbTk/EventManager.hh" 45#include "FbTk/EventManager.hh"
46#include "FbTk/StringUtil.hh" 46#include "FbTk/StringUtil.hh"
47#include "FbTk/Util.hh"
47#include "FbTk/Resource.hh" 48#include "FbTk/Resource.hh"
48#include "FbTk/SimpleCommand.hh" 49#include "FbTk/SimpleCommand.hh"
49#include "FbTk/XrmDatabaseHelper.hh" 50#include "FbTk/XrmDatabaseHelper.hh"
@@ -347,11 +348,10 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name,
347 348
348 // create screens 349 // create screens
349 for (size_t s = 0; s < screens.size(); s++) { 350 for (size_t s = 0; s < screens.size(); s++) {
350 char scrname[128], altscrname[128]; 351 std::string sc_nr = FbTk::StringUtil::number2String(screens[s]);
351 sprintf(scrname, "session.screen%d", screens[s]);
352 sprintf(altscrname, "session.Screen%d", screens[s]);
353 BScreen *screen = new BScreen(m_screen_rm.lock(), 352 BScreen *screen = new BScreen(m_screen_rm.lock(),
354 scrname, altscrname, 353 std::string("session.screen") + sc_nr,
354 std::string("session.Screen") + sc_nr,
355 screens[s], ::Layer::NUM_LAYERS); 355 screens[s], ::Layer::NUM_LAYERS);
356 356
357 // already handled 357 // already handled
@@ -576,17 +576,13 @@ void Fluxbox::setupConfigFiles() {
576 576
577#ifdef HAVE_GETPID 577#ifdef HAVE_GETPID
578 // add the fluxbox pid so fbuc can have us reload rc if necessary 578 // add the fluxbox pid so fbuc can have us reload rc if necessary
579 pid_t bpid = getpid();
580 char intbuff[64];
581 sprintf(intbuff, "%d", bpid);
582 commandargs += " -pid "; 579 commandargs += " -pid ";
583 commandargs += intbuff; 580 commandargs += FbTk::StringUtil::number2String(getpid());
584#endif // HAVE_GETPID 581#endif // HAVE_GETPID
585 582
586 FbCommands::ExecuteCmd fbuc(commandargs, 0); 583 FbCommands::ExecuteCmd fbuc(commandargs, 0);
587 fbuc.execute(); 584 fbuc.execute();
588 } 585 }
589
590} 586}
591 587
592void Fluxbox::handleEvent(XEvent * const e) { 588void Fluxbox::handleEvent(XEvent * const e) {
@@ -756,11 +752,11 @@ void Fluxbox::handleEvent(XEvent * const e) {
756 case EnterNotify: { 752 case EnterNotify: {
757 753
758 m_last_time = e->xcrossing.time; 754 m_last_time = e->xcrossing.time;
759 BScreen *screen = 0;
760 755
761 if (e->xcrossing.mode == NotifyGrab) 756 if (e->xcrossing.mode == NotifyGrab)
762 break; 757 break;
763 758
759 BScreen *screen = 0;
764 if ((e->xcrossing.window == e->xcrossing.root) && 760 if ((e->xcrossing.window == e->xcrossing.root) &&
765 (screen = searchScreen(e->xcrossing.window))) { 761 (screen = searchScreen(e->xcrossing.window))) {
766 screen->imageControl().installRootColormap(); 762 screen->imageControl().installRootColormap();
@@ -775,7 +771,7 @@ void Fluxbox::handleEvent(XEvent * const e) {
775 break; 771 break;
776 case KeyRelease: 772 case KeyRelease:
777 case KeyPress: 773 case KeyPress:
778 break; 774 break;
779 case ColormapNotify: { 775 case ColormapNotify: {
780 BScreen *screen = searchScreen(e->xcolormap.window); 776 BScreen *screen = searchScreen(e->xcolormap.window);
781 777
@@ -822,10 +818,10 @@ void Fluxbox::handleEvent(XEvent * const e) {
822 !winclient->fbwindow()->isMoving())) 818 !winclient->fbwindow()->isMoving()))
823 revertFocus(); 819 revertFocus();
824 } 820 }
825 break; 821 break;
826 case ClientMessage: 822 case ClientMessage:
827 handleClientMessage(e->xclient); 823 handleClientMessage(e->xclient);
828 break; 824 break;
829 default: { 825 default: {
830 826
831#ifdef HAVE_RANDR 827#ifdef HAVE_RANDR
@@ -1194,8 +1190,6 @@ void Fluxbox::save_rc() {
1194 _FB_USES_NLS; 1190 _FB_USES_NLS;
1195 XrmDatabase new_blackboxrc = 0; 1191 XrmDatabase new_blackboxrc = 0;
1196 1192
1197 char rc_string[1024];
1198
1199 string dbfile(getRcFilename()); 1193 string dbfile(getRcFilename());
1200 1194
1201 if (!dbfile.empty()) { 1195 if (!dbfile.empty()) {
@@ -1204,28 +1198,25 @@ void Fluxbox::save_rc() {
1204 } else 1198 } else
1205 cerr<<_FB_CONSOLETEXT(Fluxbox, BadRCFile, "rc filename is invalid!", "Bad settings file")<<endl; 1199 cerr<<_FB_CONSOLETEXT(Fluxbox, BadRCFile, "rc filename is invalid!", "Bad settings file")<<endl;
1206 1200
1201
1207 ScreenList::iterator it = m_screen_list.begin(); 1202 ScreenList::iterator it = m_screen_list.begin();
1208 ScreenList::iterator it_end = m_screen_list.end(); 1203 ScreenList::iterator it_end = m_screen_list.end();
1209
1210 //Save screen resources
1211
1212 for (; it != it_end; ++it) { 1204 for (; it != it_end; ++it) {
1213 BScreen *screen = *it; 1205 BScreen *screen = *it;
1214 int screen_number = screen->screenNumber(); 1206
1207 std::string workspaces_string("session.screen");
1208 workspaces_string += FbTk::StringUtil::number2String(screen->screenNumber());
1209 workspaces_string += ".workspaceNames: ";
1215 1210
1216 // these are static, but may not be saved in the users resource file, 1211 // these are static, but may not be saved in the users resource file,
1217 // writing these resources will allow the user to edit them at a later 1212 // writing these resources will allow the user to edit them at a later
1218 // time... but loading the defaults before saving allows us to rewrite the 1213 // time... but loading the defaults before saving allows us to rewrite the
1219 // users changes... 1214 // users changes...
1220 1215
1221 // write out the users workspace names 1216 const BScreen::WorkspaceNames& names = screen->getWorkspaceNames();
1222 sprintf(rc_string, "session.screen%d.workspaceNames: ", screen_number);
1223 string workspaces_string(rc_string);
1224
1225 const vector<string> names = screen->getWorkspaceNames();
1226 for (size_t i=0; i < names.size(); i++) { 1217 for (size_t i=0; i < names.size(); i++) {
1227 workspaces_string.append(FbTk::FbStringUtil::FbStrToLocale(names[i])); 1218 workspaces_string += FbTk::FbStringUtil::FbStrToLocale(names[i]);
1228 workspaces_string.append(","); 1219 workspaces_string += ',';
1229 } 1220 }
1230 1221
1231 XrmPutLineResource(&new_blackboxrc, workspaces_string.c_str()); 1222 XrmPutLineResource(&new_blackboxrc, workspaces_string.c_str());
@@ -1284,10 +1275,7 @@ void Fluxbox::load_rc() {
1284 m_rc_slitlistfile.setFromString(filename.c_str()); 1275 m_rc_slitlistfile.setFromString(filename.c_str());
1285 } 1276 }
1286 1277
1287 if (*m_rc_colors_per_channel < 2) 1278 *m_rc_colors_per_channel = FbTk::Util::clamp(*m_rc_colors_per_channel, 2, 6);
1288 *m_rc_colors_per_channel = 2;
1289 else if (*m_rc_colors_per_channel > 6)
1290 *m_rc_colors_per_channel = 6;
1291 1279
1292 if (m_rc_stylefile->empty()) 1280 if (m_rc_stylefile->empty())
1293 *m_rc_stylefile = DEFAULTSTYLE; 1281 *m_rc_stylefile = DEFAULTSTYLE;
@@ -1304,16 +1292,21 @@ void Fluxbox::load_rc(BScreen &screen) {
1304 if (database==0) 1292 if (database==0)
1305 database = XrmGetFileDatabase(DEFAULT_INITFILE); 1293 database = XrmGetFileDatabase(DEFAULT_INITFILE);
1306 1294
1307 XrmValue value;
1308 char *value_type, name_lookup[1024], class_lookup[1024];
1309 int screen_number = screen.screenNumber();
1310
1311 1295
1312 screen.removeWorkspaceNames(); 1296 screen.removeWorkspaceNames();
1313 1297
1314 sprintf(name_lookup, "session.screen%d.workspaceNames", screen_number); 1298 std::string screen_number = FbTk::StringUtil::number2String(screen.screenNumber());
1315 sprintf(class_lookup, "Session.Screen%d.WorkspaceNames", screen_number); 1299
1316 if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, 1300 std::string name_lookup("session.screen");
1301 name_lookup += screen_number;
1302 name_lookup += ".WorkspaceNames";
1303 std::string class_lookup("session.screen");
1304 class_lookup += screen_number;
1305 class_lookup += ".WorkspaceNames";
1306
1307 XrmValue value;
1308 char *value_type;
1309 if (XrmGetResource(*database, name_lookup.c_str(), class_lookup.c_str(), &value_type,
1317 &value)) { 1310 &value)) {
1318 1311
1319 string values(value.addr); 1312 string values(value.addr);