if someone changed the session.screen0.workspaces:<int> 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.
This commit is contained in:
mathias 2005-04-27 09:52:30 +00:00
parent 6df9d6ed54
commit b97c3db251
5 changed files with 54 additions and 44 deletions

View file

@ -1,6 +1,11 @@
(Format: Year/Month/Day)
Changes for 0.9.13
*05/04/27:
* Fix #1182770 (Mathias)
session.screen*.workspaces: <int> 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:

View file

@ -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!!

View file

@ -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());

View file

@ -30,6 +30,8 @@
#include "FbTk/ImageControl.hh"
#include <algorithm>
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;

View file

@ -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 = "<<m_resourcemanager.lockDepth()<<endl;
@ -1568,22 +1568,18 @@ void Fluxbox::load_rc(BScreen &screen) {
cerr<<__FILE__<<"("<<__FUNCTION__<<"): Workspaces="<<
screen.getNumberOfWorkspaces()<<endl;
#endif // DEBUG
char *search = StringUtil::strdup(value.addr);
int i;
for (i = 0; i < screen.getNumberOfWorkspaces(); i++) {
char *nn;
if (! i) nn = strtok(search, ",");
else nn = strtok(0, ",");
if (nn)
screen.addWorkspaceName(nn);
else break;
string values(value.addr);
BScreen::WorkspaceNames names;
StringUtil::removeTrailingWhitespace(values);
StringUtil::removeFirstWhitespace(values);
StringUtil::stringtok<BScreen::WorkspaceNames>(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();