From b97c3db25193c3b549e46910604d27e5ff92baa2 Mon Sep 17 00:00:00 2001 From: mathias Date: Wed, 27 Apr 2005 09:52:30 +0000 Subject: close #1182770 if someone changed the session.screen0.workspaces: value and fired a "reload config"/reconfigure-Command fluxbox crashed. changes: - cleaner way of reading in the workspacenames - cleaner way of initialize the workspaces in BScreen() - on BScreen::reconfigure we add/delete Workspaces to the current screen until init-file and fluxbox are in sync -> the user changed the initfile and pressed reload, so imho he wants to have the changes in the init-file realized. --- ChangeLog | 5 +++++ src/Screen.cc | 42 ++++++++++++++++++++++++------------------ src/Workspace.cc | 4 ++-- src/WorkspaceNameTool.cc | 17 ++++++++++------- src/fluxbox.cc | 30 +++++++++++++----------------- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index c439291..06306e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ (Format: Year/Month/Day) Changes for 0.9.13 *05/04/27: + * Fix #1182770 (Mathias) + session.screen*.workspaces: and the number of + workspaces in the running fluxbox were out of sync and lead to + segfault on a "reloadconfig"-Command. + fluxbox.cc Screen.cc Workspace.cc WorkspaceNameTool.cc * Fix drawing when transparency off (Simon) FbWindow.cc *05/04/26: diff --git a/src/Screen.cc b/src/Screen.cc index fae0aff..45f9693 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -328,22 +328,12 @@ BScreen::BScreen(FbTk::ResourceManager &rm, renderPosWindow(); // setup workspaces and workspace menu - - if (*resource.workspaces != 0) { - for (int i = 0; i < *resource.workspaces; ++i) { - Workspace *wkspc = new Workspace(*this, m_layermanager, - getNameOfWorkspace(m_workspaces_list.size()), - m_workspaces_list.size()); - m_workspaces_list.push_back(wkspc); - } - } else { // create at least one workspace - Workspace *wkspc = new Workspace(*this, m_layermanager, - getNameOfWorkspace(m_workspaces_list.size()), - m_workspaces_list.size()); - m_workspaces_list.push_back(wkspc); + int nr_ws = *resource.workspaces; + addWorkspace(); // at least one + for (int i = 1; i < nr_ws; ++i) { + addWorkspace(); } - m_current_workspace = m_workspaces_list.front(); @@ -656,6 +646,7 @@ void BScreen::hideWindowMenus(const FluxboxWindow* except) { void BScreen::reconfigure() { + m_windowtheme->setFocusedAlpha(*resource.focused_alpha); m_windowtheme->setUnfocusedAlpha(*resource.unfocused_alpha); m_menutheme->setAlpha(*resource.menu_alpha); @@ -688,6 +679,18 @@ void BScreen::reconfigure() { renderGeomWindow(); renderPosWindow(); + // realize the number of workspaces from the init-file + const 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(); + } + } + //reconfigure menus m_workspacemenu->reconfigure(); m_configmenu->reconfigure(); @@ -851,11 +854,16 @@ void BScreen::setAntialias(bool value) { } int BScreen::addWorkspace() { + + bool save_name = getNameOfWorkspace(m_workspaces_list.size()) != "" ? false : true; Workspace *wkspc = new Workspace(*this, m_layermanager, - "", + getNameOfWorkspace(m_workspaces_list.size()), m_workspaces_list.size()); m_workspaces_list.push_back(wkspc); - addWorkspaceName(wkspc->name().c_str()); // update names + + if (save_name) + addWorkspaceName(wkspc->name().c_str()); //update names + saveWorkspaces(m_workspaces_list.size()); updateNetizenWorkspaceCount(); @@ -879,8 +887,6 @@ int BScreen::removeLastWorkspace() { //remove last workspace m_workspaces_list.pop_back(); - - updateNetizenWorkspaceCount(); saveWorkspaces(m_workspaces_list.size()); // must be deleted after we send notify!! diff --git a/src/Workspace.cc b/src/Workspace.cc index 4985c39..8a6bdbb 100644 --- a/src/Workspace.cc +++ b/src/Workspace.cc @@ -364,7 +364,7 @@ void Workspace::update(FbTk::Subject *subj) { void Workspace::setName(const std::string &name) { - if (!name.empty()) { + if (!name.empty() && name != "") { m_name = name; } else { //if name == 0 then set default name from nls _FB_USES_NLS; @@ -375,7 +375,7 @@ void Workspace::setName(const std::string &name) { m_id + 1); //m_id starts at 0 m_name = tname; } - + screen().updateWorkspaceNamesAtom(); menu().setLabel(m_name.c_str()); diff --git a/src/WorkspaceNameTool.cc b/src/WorkspaceNameTool.cc index dbbc571..fdc4ffe 100644 --- a/src/WorkspaceNameTool.cc +++ b/src/WorkspaceNameTool.cc @@ -30,6 +30,8 @@ #include "FbTk/ImageControl.hh" +#include + WorkspaceNameTool::WorkspaceNameTool(const FbTk::FbWindow &parent, ToolTheme &theme, BScreen &screen): ToolbarItem(ToolbarItem::FIXED), @@ -68,6 +70,7 @@ void WorkspaceNameTool::moveResize(int x, int y, } void WorkspaceNameTool::update(FbTk::Subject *subj) { + m_button.setText(m_screen.currentWorkspace()->name()); if (m_button.width() != width()) { resize(width(), height()); @@ -79,13 +82,13 @@ void WorkspaceNameTool::update(FbTk::Subject *subj) { unsigned int WorkspaceNameTool::width() const { // calculate largest size - int max_size = 0; - const int num_workspaces = m_screen.getNumberOfWorkspaces(); - for (int workspace = 0; workspace < num_workspaces; ++workspace) { - const std::string &name = m_screen.getWorkspace(workspace)->name().c_str(); - int size = m_theme.font().textWidth(name.c_str(), name.size()); - if (size > max_size) - max_size = size; + unsigned int max_size = 0; + const BScreen::Workspaces& workspaces = m_screen.getWorkspacesList(); + BScreen::Workspaces::const_iterator it; + for (it = workspaces.begin(); it != workspaces.end(); it++) { + const std::string &name = (*it)->name(); + max_size = std::max(m_theme.font().textWidth(name.c_str(), name.size()), + max_size); } // so align text dont cut the last character max_size += 2; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 0865bc2..299207e 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -374,7 +374,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile } m_keyscreen = m_mousescreen = m_screen_list.front(); - + // setup theme manager to have our style file ready to be scanned FbTk::ThemeManager::instance().load(FbTk::StringUtil::expandFilename(getStyleFilename())); @@ -388,7 +388,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile m_resourcemanager.unlock(); ungrab(); - + #ifdef DEBUG if (m_resourcemanager.lockDepth() != 0) cerr<<"--- resource manager lockdepth = "<(names, values, ","); + BScreen::WorkspaceNames::iterator it; + for(it = names.begin(); it != names.end(); it++) { + if (!(*it).empty() && (*it) != "") + screen.addWorkspaceName((*it).c_str()); } - - delete [] search; + } FbTk::Image::removeAllSearchPaths(); -- cgit v0.11.2