From dbb84308855de040c043cf1c1f0ab941d6bd3be7 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 16 Jun 2011 22:36:18 +0200 Subject: 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. --- src/Screen.cc | 39 +++++++++++++++++++-------------------- src/Screen.hh | 11 ++++++++--- src/fluxbox.cc | 35 ----------------------------------- 3 files changed, 27 insertions(+), 58 deletions(-) diff --git a/src/Screen.cc b/src/Screen.cc index 373932f..6db43ac 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -243,8 +243,11 @@ const EnumTraits::Pair EnumTraits(), scrname + ".workspaceNames"), opaque_move(rm, true, scrname + ".opaqueMove"), full_max(rm, false, scrname+".fullMaximization"), max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"), @@ -388,9 +391,6 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, Keys::GLOBAL|Keys::ON_DESKTOP); rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); - // load this screens resources - fluxbox->load_rc(*this); - // setup image cache engine m_image_control.reset(new FbTk::ImageControl(scrn, fluxbox->colorsPerChannel(), @@ -856,15 +856,14 @@ void BScreen::reconfigure() { // realize the number of workspaces from the init-file const unsigned int nr_ws = *resource.workspaces; - if (nr_ws > m_workspaces_list.size()) { - while(nr_ws != m_workspaces_list.size()) { - addWorkspace(); - } - } else if (nr_ws < m_workspaces_list.size()) { - while(nr_ws != m_workspaces_list.size()) { - removeLastWorkspace(); - } - } + while(nr_ws > m_workspaces_list.size()) + addWorkspace(); + while(nr_ws < m_workspaces_list.size()) + removeLastWorkspace(); + + // and update their names + for(size_t i = 0; i < std::min(m_workspaces_list.size(), resource.workspace_names->size()); ++i) + m_workspaces_list[i]->setName( (*resource.workspace_names)[i] ); // update menu filenames m_rootmenu->reloadHelper()->setMainFile(fluxbox->getMenuFilename()); @@ -904,14 +903,14 @@ void BScreen::reconfigureTabs() { void BScreen::updateWorkspaceName(unsigned int w) { Workspace *space = getWorkspace(w); if (space) { - m_workspace_names[w] = space->name(); + (*resource.workspace_names)[w] = space->name(); m_workspacenames_sig.emit(*this); Fluxbox::instance()->save_rc(); } } void BScreen::removeWorkspaceNames() { - m_workspace_names.clear(); + resource.workspace_names->clear(); } void BScreen::addIcon(FluxboxWindow *w) { @@ -1345,17 +1344,17 @@ void BScreen::updateAvailableWorkspaceArea() { m_workspace_area_sig.emit(*this); } -void BScreen::addWorkspaceName(const char *name) { - m_workspace_names.push_back(FbTk::FbStringUtil::LocaleStrToFb(name)); - Workspace *wkspc = getWorkspace(m_workspace_names.size()-1); +void BScreen::addWorkspaceName(const std::string &name) { + resource.workspace_names->push_back(name); + Workspace *wkspc = getWorkspace(resource.workspace_names->size()-1); if (wkspc) - wkspc->setName(m_workspace_names.back()); + wkspc->setName(name); } string BScreen::getNameOfWorkspace(unsigned int workspace) const { - if (workspace < m_workspace_names.size()) - return m_workspace_names[workspace]; + if (workspace < resource.workspace_names->size()) + return (*resource.workspace_names)[workspace]; else return ""; } 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: const Workspaces &getWorkspacesList() const { return m_workspaces_list; } Workspaces &getWorkspacesList() { return m_workspaces_list; } - const WorkspaceNames &getWorkspaceNames() const { return m_workspace_names; } + const WorkspaceNames &getWorkspaceNames() const { return *resource.workspace_names; } /** @name Screen signals */ @@ -322,7 +322,7 @@ public: /// remove all workspace names void removeWorkspaceNames(); /// add a workspace name to the end of the workspace name list - void addWorkspaceName(const char *name); + void addWorkspaceName(const std::string &name); /// add a window to the icon list void addIcon(FluxboxWindow *win); /// remove a window from the icon list @@ -510,7 +510,6 @@ private: Workspace *m_current_workspace; - WorkspaceNames m_workspace_names; Workspaces m_workspaces_list; std::auto_ptr m_focused_windowtheme, @@ -528,6 +527,12 @@ private: struct ScreenResource { ScreenResource(FbTk::ResourceManager_base &rm, const std::string &scrname); + static const char workspace_names_delim[]; + FbTk::Resource< + std::vector, + FbTk::VectorTraits + > workspace_names; + FbTk::BoolResource opaque_move, full_max, max_ignore_inc, max_disable_move, max_disable_resize, workspace_warping, show_window_pos, auto_raise, click_raises; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index efb89b8..cda71ba 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -1131,36 +1131,6 @@ void Fluxbox::save_rc() { cerr<<_FB_CONSOLETEXT(Fluxbox, BadRCFile, "rc filename is invalid!", "Bad settings file")<screenNumber()); - workspaces_string += ".workspaceNames: "; - - // these are static, but may not be saved in the users resource file, - // writing these resources will allow the user to edit them at a later - // time... but loading the defaults before saving allows us to rewrite the - // users changes... - - const BScreen::WorkspaceNames& names = screen->getWorkspaceNames(); - for (size_t i=0; i < names.size(); i++) { - workspaces_string += FbTk::FbStringUtil::FbStrToLocale(names[i]); - workspaces_string += ','; - } - - XrmPutLineResource(&new_rc, workspaces_string.c_str()); - - } - - XrmDatabase old_rc = XrmGetFileDatabase(dbfile.c_str()); - - XrmMergeDatabases(new_rc, &old_rc); - XrmPutFileDatabase(old_rc, dbfile.c_str()); - XrmDestroyDatabase(old_rc); - fbdbg<<__FILE__<<"("<<__LINE__<<"): ------------ SAVING DONE"<reconfigure(); STLUtil::forAll(m_atomhandler, mem_fun(&AtomHandler::reconfigure)); -- cgit v0.11.2