diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-16 20:36:18 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-06-16 20:37:47 (GMT) |
commit | 25e1ea47997fc8bd858400cdf89dbe32db97bbcc (patch) | |
tree | 95819011a3371d2ce93b68d9e955632b71d52018 | |
parent | 56ca54a6f0e1c1dd806e9e93579c168b337e438c (diff) | |
download | fluxbox_pavel-25e1ea47997fc8bd858400cdf89dbe32db97bbcc.zip fluxbox_pavel-25e1ea47997fc8bd858400cdf89dbe32db97bbcc.tar.bz2 |
Make session.screenX.workspace_names a real FbTk::Resource
instead of the add-on hack it was.
This also fixes a lot of problems with saving of config.
-rw-r--r-- | src/Screen.cc | 39 | ||||
-rw-r--r-- | src/Screen.hh | 11 | ||||
-rw-r--r-- | src/fluxbox.cc | 79 |
3 files changed, 27 insertions, 102 deletions
diff --git a/src/Screen.cc b/src/Screen.cc index 114c440..3a1ec2d 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -243,8 +243,11 @@ const EnumTraits<FbWinFrame::TabPlacement>::Pair EnumTraits<FbWinFrame::TabPlace | |||
243 | } // end namespace FbTk | 243 | } // end namespace FbTk |
244 | 244 | ||
245 | 245 | ||
246 | const char BScreen::ScreenResource::workspace_names_delim[] = ","; | ||
247 | |||
246 | BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, | 248 | BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, |
247 | const string &scrname): | 249 | const string &scrname): |
250 | workspace_names(rm, std::vector<std::string>(), scrname + ".workspaceNames"), | ||
248 | opaque_move(rm, true, scrname + ".opaqueMove"), | 251 | opaque_move(rm, true, scrname + ".opaqueMove"), |
249 | full_max(rm, false, scrname+".fullMaximization"), | 252 | full_max(rm, false, scrname+".fullMaximization"), |
250 | max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"), | 253 | max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"), |
@@ -388,9 +391,6 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, | |||
388 | Keys::GLOBAL|Keys::ON_DESKTOP); | 391 | Keys::GLOBAL|Keys::ON_DESKTOP); |
389 | rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); | 392 | rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); |
390 | 393 | ||
391 | // load this screens resources | ||
392 | fluxbox->load_rc(*this); | ||
393 | |||
394 | // setup image cache engine | 394 | // setup image cache engine |
395 | m_image_control.reset(new FbTk::ImageControl(scrn, | 395 | m_image_control.reset(new FbTk::ImageControl(scrn, |
396 | fluxbox->colorsPerChannel(), | 396 | fluxbox->colorsPerChannel(), |
@@ -864,15 +864,14 @@ void BScreen::reconfigure() { | |||
864 | 864 | ||
865 | // realize the number of workspaces from the init-file | 865 | // realize the number of workspaces from the init-file |
866 | const unsigned int nr_ws = *resource.workspaces; | 866 | const unsigned int nr_ws = *resource.workspaces; |
867 | if (nr_ws > m_workspaces_list.size()) { | 867 | while(nr_ws > m_workspaces_list.size()) |
868 | while(nr_ws != m_workspaces_list.size()) { | 868 | addWorkspace(); |
869 | addWorkspace(); | 869 | while(nr_ws < m_workspaces_list.size()) |
870 | } | 870 | removeLastWorkspace(); |
871 | } else if (nr_ws < m_workspaces_list.size()) { | 871 | |
872 | while(nr_ws != m_workspaces_list.size()) { | 872 | // and update their names |
873 | removeLastWorkspace(); | 873 | for(size_t i = 0; i < std::min(m_workspaces_list.size(), resource.workspace_names->size()); ++i) |
874 | } | 874 | m_workspaces_list[i]->setName( (*resource.workspace_names)[i] ); |
875 | } | ||
876 | 875 | ||
877 | // update menu filenames | 876 | // update menu filenames |
878 | m_rootmenu->reloadHelper()->setMainFile(fluxbox->getMenuFilename()); | 877 | m_rootmenu->reloadHelper()->setMainFile(fluxbox->getMenuFilename()); |
@@ -912,14 +911,14 @@ void BScreen::reconfigureTabs() { | |||
912 | void BScreen::updateWorkspaceName(unsigned int w) { | 911 | void BScreen::updateWorkspaceName(unsigned int w) { |
913 | Workspace *space = getWorkspace(w); | 912 | Workspace *space = getWorkspace(w); |
914 | if (space) { | 913 | if (space) { |
915 | m_workspace_names[w] = space->name(); | 914 | (*resource.workspace_names)[w] = space->name(); |
916 | m_workspacenames_sig.emit(*this); | 915 | m_workspacenames_sig.emit(*this); |
917 | Fluxbox::instance()->save_rc(); | 916 | Fluxbox::instance()->save_rc(); |
918 | } | 917 | } |
919 | } | 918 | } |
920 | 919 | ||
921 | void BScreen::removeWorkspaceNames() { | 920 | void BScreen::removeWorkspaceNames() { |
922 | m_workspace_names.clear(); | 921 | resource.workspace_names->clear(); |
923 | } | 922 | } |
924 | 923 | ||
925 | void BScreen::addIcon(FluxboxWindow *w) { | 924 | void BScreen::addIcon(FluxboxWindow *w) { |
@@ -1353,17 +1352,17 @@ void BScreen::updateAvailableWorkspaceArea() { | |||
1353 | m_workspace_area_sig.emit(*this); | 1352 | m_workspace_area_sig.emit(*this); |
1354 | } | 1353 | } |
1355 | 1354 | ||
1356 | void BScreen::addWorkspaceName(const char *name) { | 1355 | void BScreen::addWorkspaceName(const std::string &name) { |
1357 | m_workspace_names.push_back(FbTk::FbStringUtil::LocaleStrToFb(name)); | 1356 | resource.workspace_names->push_back(name); |
1358 | Workspace *wkspc = getWorkspace(m_workspace_names.size()-1); | 1357 | Workspace *wkspc = getWorkspace(resource.workspace_names->size()-1); |
1359 | if (wkspc) | 1358 | if (wkspc) |
1360 | wkspc->setName(m_workspace_names.back()); | 1359 | wkspc->setName(name); |
1361 | } | 1360 | } |
1362 | 1361 | ||
1363 | 1362 | ||
1364 | string BScreen::getNameOfWorkspace(unsigned int workspace) const { | 1363 | string BScreen::getNameOfWorkspace(unsigned int workspace) const { |
1365 | if (workspace < m_workspace_names.size()) | 1364 | if (workspace < resource.workspace_names->size()) |
1366 | return m_workspace_names[workspace]; | 1365 | return (*resource.workspace_names)[workspace]; |
1367 | else | 1366 | else |
1368 | return ""; | 1367 | return ""; |
1369 | } | 1368 | } |
diff --git a/src/Screen.hh b/src/Screen.hh index e7b439c..138cd1c 100644 --- a/src/Screen.hh +++ b/src/Screen.hh | |||
@@ -190,7 +190,7 @@ public: | |||
190 | 190 | ||
191 | const Workspaces &getWorkspacesList() const { return m_workspaces_list; } | 191 | const Workspaces &getWorkspacesList() const { return m_workspaces_list; } |
192 | Workspaces &getWorkspacesList() { return m_workspaces_list; } | 192 | Workspaces &getWorkspacesList() { return m_workspaces_list; } |
193 | const WorkspaceNames &getWorkspaceNames() const { return m_workspace_names; } | 193 | const WorkspaceNames &getWorkspaceNames() const { return *resource.workspace_names; } |
194 | /** | 194 | /** |
195 | @name Screen signals | 195 | @name Screen signals |
196 | */ | 196 | */ |
@@ -321,7 +321,7 @@ public: | |||
321 | /// remove all workspace names | 321 | /// remove all workspace names |
322 | void removeWorkspaceNames(); | 322 | void removeWorkspaceNames(); |
323 | /// add a workspace name to the end of the workspace name list | 323 | /// add a workspace name to the end of the workspace name list |
324 | void addWorkspaceName(const char *name); | 324 | void addWorkspaceName(const std::string &name); |
325 | /// add a window to the icon list | 325 | /// add a window to the icon list |
326 | void addIcon(FluxboxWindow *win); | 326 | void addIcon(FluxboxWindow *win); |
327 | /// remove a window from the icon list | 327 | /// remove a window from the icon list |
@@ -493,7 +493,6 @@ private: | |||
493 | 493 | ||
494 | Workspace *m_current_workspace; | 494 | Workspace *m_current_workspace; |
495 | 495 | ||
496 | WorkspaceNames m_workspace_names; | ||
497 | Workspaces m_workspaces_list; | 496 | Workspaces m_workspaces_list; |
498 | 497 | ||
499 | std::auto_ptr<FbWinFrameTheme> m_focused_windowtheme, | 498 | std::auto_ptr<FbWinFrameTheme> m_focused_windowtheme, |
@@ -511,6 +510,12 @@ private: | |||
511 | struct ScreenResource { | 510 | struct ScreenResource { |
512 | ScreenResource(FbTk::ResourceManager_base &rm, const std::string &scrname); | 511 | ScreenResource(FbTk::ResourceManager_base &rm, const std::string &scrname); |
513 | 512 | ||
513 | static const char workspace_names_delim[]; | ||
514 | FbTk::Resource< | ||
515 | std::vector<std::string>, | ||
516 | FbTk::VectorTraits<FbTk::StringTraits, workspace_names_delim> | ||
517 | > workspace_names; | ||
518 | |||
514 | FbTk::BoolResource opaque_move, full_max, | 519 | FbTk::BoolResource opaque_move, full_max, |
515 | max_ignore_inc, max_disable_move, max_disable_resize, | 520 | max_ignore_inc, max_disable_move, max_disable_resize, |
516 | workspace_warping, show_window_pos, auto_raise, click_raises; | 521 | workspace_warping, show_window_pos, auto_raise, click_raises; |
diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 635f383..8520298 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc | |||
@@ -1132,36 +1132,6 @@ void Fluxbox::save_rc() { | |||
1132 | cerr<<_FB_CONSOLETEXT(Fluxbox, BadRCFile, "rc filename is invalid!", "Bad settings file")<<endl; | 1132 | cerr<<_FB_CONSOLETEXT(Fluxbox, BadRCFile, "rc filename is invalid!", "Bad settings file")<<endl; |
1133 | 1133 | ||
1134 | 1134 | ||
1135 | ScreenList::iterator it = m_screen_list.begin(); | ||
1136 | ScreenList::iterator it_end = m_screen_list.end(); | ||
1137 | for (; it != it_end; ++it) { | ||
1138 | BScreen *screen = *it; | ||
1139 | |||
1140 | std::string workspaces_string("screen"); | ||
1141 | workspaces_string += FbTk::StringUtil::number2String(screen->screenNumber()); | ||
1142 | workspaces_string += ".workspaceNames: "; | ||
1143 | |||
1144 | // these are static, but may not be saved in the users resource file, | ||
1145 | // writing these resources will allow the user to edit them at a later | ||
1146 | // time... but loading the defaults before saving allows us to rewrite the | ||
1147 | // users changes... | ||
1148 | |||
1149 | const BScreen::WorkspaceNames& names = screen->getWorkspaceNames(); | ||
1150 | for (size_t i=0; i < names.size(); i++) { | ||
1151 | workspaces_string += FbTk::FbStringUtil::FbStrToLocale(names[i]); | ||
1152 | workspaces_string += ','; | ||
1153 | } | ||
1154 | |||
1155 | XrmPutLineResource(&new_rc, workspaces_string.c_str()); | ||
1156 | |||
1157 | } | ||
1158 | |||
1159 | XrmDatabase old_rc = XrmGetFileDatabase(dbfile.c_str()); | ||
1160 | |||
1161 | XrmMergeDatabases(new_rc, &old_rc); | ||
1162 | XrmPutFileDatabase(old_rc, dbfile.c_str()); | ||
1163 | XrmDestroyDatabase(old_rc); | ||
1164 | |||
1165 | fbdbg<<__FILE__<<"("<<__LINE__<<"): ------------ SAVING DONE"<<endl; | 1135 | fbdbg<<__FILE__<<"("<<__LINE__<<"): ------------ SAVING DONE"<<endl; |
1166 | 1136 | ||
1167 | } | 1137 | } |
@@ -1219,50 +1189,6 @@ void Fluxbox::load_rc() { | |||
1219 | *m_rc_stylefile = DEFAULTSTYLE; | 1189 | *m_rc_stylefile = DEFAULTSTYLE; |
1220 | } | 1190 | } |
1221 | 1191 | ||
1222 | void Fluxbox::load_rc(BScreen &screen) { | ||
1223 | //get resource filename | ||
1224 | _FB_USES_NLS; | ||
1225 | string dbfile(getRcFilename()); | ||
1226 | |||
1227 | XrmDatabaseHelper database; | ||
1228 | |||
1229 | // XXX make this a regular resource | ||
1230 | database = XrmGetFileDatabase(dbfile.c_str()); | ||
1231 | if (database==0) | ||
1232 | database = XrmGetFileDatabase(DEFAULT_INITFILE); | ||
1233 | |||
1234 | |||
1235 | screen.removeWorkspaceNames(); | ||
1236 | |||
1237 | std::string screen_number = FbTk::StringUtil::number2String(screen.screenNumber()); | ||
1238 | |||
1239 | std::string name_lookup("screen"); | ||
1240 | name_lookup += screen_number; | ||
1241 | name_lookup += ".workspaceNames"; | ||
1242 | std::string class_lookup("screen"); | ||
1243 | class_lookup += screen_number; | ||
1244 | class_lookup += ".WorkspaceNames"; | ||
1245 | |||
1246 | XrmValue value; | ||
1247 | char *value_type; | ||
1248 | if (XrmGetResource(*database, name_lookup.c_str(), class_lookup.c_str(), &value_type, | ||
1249 | &value)) { | ||
1250 | |||
1251 | string values(value.addr); | ||
1252 | BScreen::WorkspaceNames names; | ||
1253 | |||
1254 | StringUtil::removeTrailingWhitespace(values); | ||
1255 | StringUtil::removeFirstWhitespace(values); | ||
1256 | StringUtil::stringtok<BScreen::WorkspaceNames>(names, values, ","); | ||
1257 | BScreen::WorkspaceNames::iterator it; | ||
1258 | for(it = names.begin(); it != names.end(); it++) { | ||
1259 | if (!(*it).empty() && (*it) != "") | ||
1260 | screen.addWorkspaceName((*it).c_str()); | ||
1261 | } | ||
1262 | |||
1263 | } | ||
1264 | } | ||
1265 | |||
1266 | void Fluxbox::reconfigure() { | 1192 | void Fluxbox::reconfigure() { |
1267 | load_rc(); | 1193 | load_rc(); |
1268 | m_reconfigure_wait = true; | 1194 | m_reconfigure_wait = true; |
@@ -1274,11 +1200,6 @@ void Fluxbox::real_reconfigure() { | |||
1274 | 1200 | ||
1275 | FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); | 1201 | FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); |
1276 | 1202 | ||
1277 | ScreenList::iterator screen_it = m_screen_list.begin(); | ||
1278 | ScreenList::iterator screen_it_end = m_screen_list.end(); | ||
1279 | for (; screen_it != screen_it_end; ++screen_it) | ||
1280 | load_rc(*(*screen_it)); | ||
1281 | |||
1282 | STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); | 1203 | STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); |
1283 | m_key->reconfigure(); | 1204 | m_key->reconfigure(); |
1284 | STLUtil::forAll(m_atomhandler, mem_fun(&AtomHandler::reconfigure)); | 1205 | STLUtil::forAll(m_atomhandler, mem_fun(&AtomHandler::reconfigure)); |