diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-16 20:36:18 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-17 00:05:25 (GMT) |
commit | 90f38a5a2d90af45059dd022d38214068e1b0ebd (patch) | |
tree | 75268600a34c6a952aa5dbd1fe854df3ee17a30d | |
parent | 38e455148c19de101abcb7696b28f109f42aec6b (diff) | |
download | fluxbox_pavel-90f38a5a2d90af45059dd022d38214068e1b0ebd.zip fluxbox_pavel-90f38a5a2d90af45059dd022d38214068e1b0ebd.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 027f542..24e086c 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -261,8 +261,11 @@ const EnumTraits<FbWinFrame::TabPlacement>::Pair EnumTraits<FbWinFrame::TabPlace | |||
261 | } // end namespace FbTk | 261 | } // end namespace FbTk |
262 | 262 | ||
263 | 263 | ||
264 | const char BScreen::ScreenResource::workspace_names_delim[] = ","; | ||
265 | |||
264 | BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, | 266 | BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, |
265 | const string &scrname): | 267 | const string &scrname): |
268 | workspace_names(rm, std::vector<std::string>(), scrname + ".workspaceNames"), | ||
266 | opaque_move(rm, true, scrname + ".opaqueMove"), | 269 | opaque_move(rm, true, scrname + ".opaqueMove"), |
267 | full_max(rm, false, scrname+".fullMaximization"), | 270 | full_max(rm, false, scrname+".fullMaximization"), |
268 | max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"), | 271 | max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"), |
@@ -414,9 +417,6 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, | |||
414 | Keys::GLOBAL|Keys::ON_DESKTOP); | 417 | Keys::GLOBAL|Keys::ON_DESKTOP); |
415 | rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); | 418 | rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); |
416 | 419 | ||
417 | // load this screens resources | ||
418 | fluxbox->load_rc(*this); | ||
419 | |||
420 | // setup image cache engine | 420 | // setup image cache engine |
421 | m_image_control.reset(new FbTk::ImageControl(scrn, | 421 | m_image_control.reset(new FbTk::ImageControl(scrn, |
422 | fluxbox->colorsPerChannel(), | 422 | fluxbox->colorsPerChannel(), |
@@ -879,15 +879,14 @@ void BScreen::reconfigure() { | |||
879 | 879 | ||
880 | // realize the number of workspaces from the init-file | 880 | // realize the number of workspaces from the init-file |
881 | const unsigned int nr_ws = *resource.workspaces; | 881 | const unsigned int nr_ws = *resource.workspaces; |
882 | if (nr_ws > m_workspaces_list.size()) { | 882 | while(nr_ws > m_workspaces_list.size()) |
883 | while(nr_ws != m_workspaces_list.size()) { | 883 | addWorkspace(); |
884 | addWorkspace(); | 884 | while(nr_ws < m_workspaces_list.size()) |
885 | } | 885 | removeLastWorkspace(); |
886 | } else if (nr_ws < m_workspaces_list.size()) { | 886 | |
887 | while(nr_ws != m_workspaces_list.size()) { | 887 | // and update their names |
888 | removeLastWorkspace(); | 888 | for(size_t i = 0; i < std::min(m_workspaces_list.size(), resource.workspace_names->size()); ++i) |
889 | } | 889 | m_workspaces_list[i]->setName( (*resource.workspace_names)[i] ); |
890 | } | ||
891 | 890 | ||
892 | // update menu filenames | 891 | // update menu filenames |
893 | m_rootmenu->reloadHelper()->setMainFile(fluxbox->getMenuFilename()); | 892 | m_rootmenu->reloadHelper()->setMainFile(fluxbox->getMenuFilename()); |
@@ -927,14 +926,14 @@ void BScreen::reconfigureTabs() { | |||
927 | void BScreen::updateWorkspaceName(unsigned int w) { | 926 | void BScreen::updateWorkspaceName(unsigned int w) { |
928 | Workspace *space = getWorkspace(w); | 927 | Workspace *space = getWorkspace(w); |
929 | if (space) { | 928 | if (space) { |
930 | m_workspace_names[w] = space->name(); | 929 | (*resource.workspace_names)[w] = space->name(); |
931 | m_workspacenames_sig.emit(*this); | 930 | m_workspacenames_sig.emit(*this); |
932 | Fluxbox::instance()->save_rc(); | 931 | Fluxbox::instance()->save_rc(); |
933 | } | 932 | } |
934 | } | 933 | } |
935 | 934 | ||
936 | void BScreen::removeWorkspaceNames() { | 935 | void BScreen::removeWorkspaceNames() { |
937 | m_workspace_names.clear(); | 936 | resource.workspace_names->clear(); |
938 | } | 937 | } |
939 | 938 | ||
940 | void BScreen::addIcon(FluxboxWindow *w) { | 939 | void BScreen::addIcon(FluxboxWindow *w) { |
@@ -1364,17 +1363,17 @@ void BScreen::updateAvailableWorkspaceArea() { | |||
1364 | m_workspace_area_sig.emit(*this); | 1363 | m_workspace_area_sig.emit(*this); |
1365 | } | 1364 | } |
1366 | 1365 | ||
1367 | void BScreen::addWorkspaceName(const char *name) { | 1366 | void BScreen::addWorkspaceName(const std::string &name) { |
1368 | m_workspace_names.push_back(FbTk::FbStringUtil::LocaleStrToFb(name)); | 1367 | resource.workspace_names->push_back(name); |
1369 | Workspace *wkspc = getWorkspace(m_workspace_names.size()-1); | 1368 | Workspace *wkspc = getWorkspace(resource.workspace_names->size()-1); |
1370 | if (wkspc) | 1369 | if (wkspc) |
1371 | wkspc->setName(m_workspace_names.back()); | 1370 | wkspc->setName(name); |
1372 | } | 1371 | } |
1373 | 1372 | ||
1374 | 1373 | ||
1375 | string BScreen::getNameOfWorkspace(unsigned int workspace) const { | 1374 | string BScreen::getNameOfWorkspace(unsigned int workspace) const { |
1376 | if (workspace < m_workspace_names.size()) | 1375 | if (workspace < resource.workspace_names->size()) |
1377 | return m_workspace_names[workspace]; | 1376 | return (*resource.workspace_names)[workspace]; |
1378 | else | 1377 | else |
1379 | return ""; | 1378 | return ""; |
1380 | } | 1379 | } |
diff --git a/src/Screen.hh b/src/Screen.hh index 05005f0..8c89ab2 100644 --- a/src/Screen.hh +++ b/src/Screen.hh | |||
@@ -191,7 +191,7 @@ public: | |||
191 | 191 | ||
192 | const Workspaces &getWorkspacesList() const { return m_workspaces_list; } | 192 | const Workspaces &getWorkspacesList() const { return m_workspaces_list; } |
193 | Workspaces &getWorkspacesList() { return m_workspaces_list; } | 193 | Workspaces &getWorkspacesList() { return m_workspaces_list; } |
194 | const WorkspaceNames &getWorkspaceNames() const { return m_workspace_names; } | 194 | const WorkspaceNames &getWorkspaceNames() const { return *resource.workspace_names; } |
195 | /** | 195 | /** |
196 | @name Screen signals | 196 | @name Screen signals |
197 | */ | 197 | */ |
@@ -322,7 +322,7 @@ public: | |||
322 | /// remove all workspace names | 322 | /// remove all workspace names |
323 | void removeWorkspaceNames(); | 323 | void removeWorkspaceNames(); |
324 | /// add a workspace name to the end of the workspace name list | 324 | /// add a workspace name to the end of the workspace name list |
325 | void addWorkspaceName(const char *name); | 325 | void addWorkspaceName(const std::string &name); |
326 | /// add a window to the icon list | 326 | /// add a window to the icon list |
327 | void addIcon(FluxboxWindow *win); | 327 | void addIcon(FluxboxWindow *win); |
328 | /// remove a window from the icon list | 328 | /// remove a window from the icon list |
@@ -510,7 +510,6 @@ private: | |||
510 | 510 | ||
511 | Workspace *m_current_workspace; | 511 | Workspace *m_current_workspace; |
512 | 512 | ||
513 | WorkspaceNames m_workspace_names; | ||
514 | Workspaces m_workspaces_list; | 513 | Workspaces m_workspaces_list; |
515 | 514 | ||
516 | std::auto_ptr<FbWinFrameTheme> m_focused_windowtheme, | 515 | std::auto_ptr<FbWinFrameTheme> m_focused_windowtheme, |
@@ -528,6 +527,12 @@ private: | |||
528 | struct ScreenResource { | 527 | struct ScreenResource { |
529 | ScreenResource(FbTk::ResourceManager_base &rm, const std::string &scrname); | 528 | ScreenResource(FbTk::ResourceManager_base &rm, const std::string &scrname); |
530 | 529 | ||
530 | static const char workspace_names_delim[]; | ||
531 | FbTk::Resource< | ||
532 | std::vector<std::string>, | ||
533 | FbTk::VectorTraits<FbTk::StringTraits, workspace_names_delim> | ||
534 | > workspace_names; | ||
535 | |||
531 | FbTk::BoolResource opaque_move, full_max, | 536 | FbTk::BoolResource opaque_move, full_max, |
532 | max_ignore_inc, max_disable_move, max_disable_resize, | 537 | max_ignore_inc, max_disable_move, max_disable_resize, |
533 | workspace_warping, show_window_pos, auto_raise, click_raises; | 538 | workspace_warping, show_window_pos, auto_raise, click_raises; |
diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 7d0fc15..44b95b1 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc | |||
@@ -1140,36 +1140,6 @@ void Fluxbox::save_rc() { | |||
1140 | cerr<<_FB_CONSOLETEXT(Fluxbox, BadRCFile, "rc filename is invalid!", "Bad settings file")<<endl; | 1140 | cerr<<_FB_CONSOLETEXT(Fluxbox, BadRCFile, "rc filename is invalid!", "Bad settings file")<<endl; |
1141 | 1141 | ||
1142 | 1142 | ||
1143 | ScreenList::iterator it = m_screen_list.begin(); | ||
1144 | ScreenList::iterator it_end = m_screen_list.end(); | ||
1145 | for (; it != it_end; ++it) { | ||
1146 | BScreen *screen = *it; | ||
1147 | |||
1148 | std::string workspaces_string("screen"); | ||
1149 | workspaces_string += FbTk::StringUtil::number2String(screen->screenNumber()); | ||
1150 | workspaces_string += ".workspaceNames: "; | ||
1151 | |||
1152 | // these are static, but may not be saved in the users resource file, | ||
1153 | // writing these resources will allow the user to edit them at a later | ||
1154 | // time... but loading the defaults before saving allows us to rewrite the | ||
1155 | // users changes... | ||
1156 | |||
1157 | const BScreen::WorkspaceNames& names = screen->getWorkspaceNames(); | ||
1158 | for (size_t i=0; i < names.size(); i++) { | ||
1159 | workspaces_string += FbTk::FbStringUtil::FbStrToLocale(names[i]); | ||
1160 | workspaces_string += ','; | ||
1161 | } | ||
1162 | |||
1163 | XrmPutLineResource(&new_rc, workspaces_string.c_str()); | ||
1164 | |||
1165 | } | ||
1166 | |||
1167 | XrmDatabase old_rc = XrmGetFileDatabase(dbfile.c_str()); | ||
1168 | |||
1169 | XrmMergeDatabases(new_rc, &old_rc); | ||
1170 | XrmPutFileDatabase(old_rc, dbfile.c_str()); | ||
1171 | XrmDestroyDatabase(old_rc); | ||
1172 | |||
1173 | fbdbg<<__FILE__<<"("<<__LINE__<<"): ------------ SAVING DONE"<<endl; | 1143 | fbdbg<<__FILE__<<"("<<__LINE__<<"): ------------ SAVING DONE"<<endl; |
1174 | 1144 | ||
1175 | } | 1145 | } |
@@ -1227,50 +1197,6 @@ void Fluxbox::load_rc() { | |||
1227 | *m_rc_stylefile = DEFAULTSTYLE; | 1197 | *m_rc_stylefile = DEFAULTSTYLE; |
1228 | } | 1198 | } |
1229 | 1199 | ||
1230 | void Fluxbox::load_rc(BScreen &screen) { | ||
1231 | //get resource filename | ||
1232 | _FB_USES_NLS; | ||
1233 | string dbfile(getRcFilename()); | ||
1234 | |||
1235 | XrmDatabaseHelper database; | ||
1236 | |||
1237 | // XXX make this a regular resource | ||
1238 | database = XrmGetFileDatabase(dbfile.c_str()); | ||
1239 | if (database==0) | ||
1240 | database = XrmGetFileDatabase(DEFAULT_INITFILE); | ||
1241 | |||
1242 | |||
1243 | screen.removeWorkspaceNames(); | ||
1244 | |||
1245 | std::string screen_number = FbTk::StringUtil::number2String(screen.screenNumber()); | ||
1246 | |||
1247 | std::string name_lookup("screen"); | ||
1248 | name_lookup += screen_number; | ||
1249 | name_lookup += ".workspaceNames"; | ||
1250 | std::string class_lookup("screen"); | ||
1251 | class_lookup += screen_number; | ||
1252 | class_lookup += ".WorkspaceNames"; | ||
1253 | |||
1254 | XrmValue value; | ||
1255 | char *value_type; | ||
1256 | if (XrmGetResource(*database, name_lookup.c_str(), class_lookup.c_str(), &value_type, | ||
1257 | &value)) { | ||
1258 | |||
1259 | string values(value.addr); | ||
1260 | BScreen::WorkspaceNames names; | ||
1261 | |||
1262 | StringUtil::removeTrailingWhitespace(values); | ||
1263 | StringUtil::removeFirstWhitespace(values); | ||
1264 | StringUtil::stringtok<BScreen::WorkspaceNames>(names, values, ","); | ||
1265 | BScreen::WorkspaceNames::iterator it; | ||
1266 | for(it = names.begin(); it != names.end(); ++it) { | ||
1267 | if (!(*it).empty() && (*it) != "") | ||
1268 | screen.addWorkspaceName((*it).c_str()); | ||
1269 | } | ||
1270 | |||
1271 | } | ||
1272 | } | ||
1273 | |||
1274 | void Fluxbox::reconfigure() { | 1200 | void Fluxbox::reconfigure() { |
1275 | load_rc(); | 1201 | load_rc(); |
1276 | m_reconfigure_wait = true; | 1202 | m_reconfigure_wait = true; |
@@ -1282,11 +1208,6 @@ void Fluxbox::real_reconfigure() { | |||
1282 | 1208 | ||
1283 | FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); | 1209 | FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); |
1284 | 1210 | ||
1285 | ScreenList::iterator screen_it = m_screen_list.begin(); | ||
1286 | ScreenList::iterator screen_it_end = m_screen_list.end(); | ||
1287 | for (; screen_it != screen_it_end; ++screen_it) | ||
1288 | load_rc(*(*screen_it)); | ||
1289 | |||
1290 | STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); | 1211 | STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); |
1291 | m_key->reconfigure(); | 1212 | m_key->reconfigure(); |
1292 | STLUtil::forAll(m_atomhandler, mem_fun(&AtomHandler::reconfigure)); | 1213 | STLUtil::forAll(m_atomhandler, mem_fun(&AtomHandler::reconfigure)); |